Where to place you own .sty or .cls files, to make them available to all my .tex files?

Suppose you have defined a package or a class, but how do you make it available at all times? One way is to just place it in the same folder as the .tex file, but that’s not what I’m after here. This post will tell you a way to “install” the package centrally on your computer.

1. Find out the directory. First, use this command at the command prompt to find out where your TeX home directory is.

kpsewhich -var-value=TEXMFHOME
OS Location
Windows C:/Users/stefan/texmf
Unix-type ~/texmf/
Mac ~/Library/texmf

2. Place files in the “right place”. Following the TeX directory structure, you should place your file in the “right place” like ~/texmf/tex/latex/packagename/packagename.sty. For a TDS-conformant system (TeX Directory Structure), the “right place” for a LaTeX .sty file is a suitably-named subdirectory of texmf/tex/latex/. For a full list of “right place”s, please see LaTeX/Installing Extra Packages. Moreover, for the beamer style, put the theme under beamer/themes/ with “color”, “font”, “inner”, “outer”, and “theme” in seperated subdirectories.

read more

Dropbox icon is not working Xubuntu 16.04 LTS

After upgrading to Xubuntu 16.04, I found that the dropbox icon stopped working. The icon is black with a red slashed zero. I cannot click on it to bring up the dropbox menu.

The reason is that Dropbox starts to use “indicator area” for their tray icon instead of “notification area”. The problem can be fixed by running

$ dropbox stop && DBUS_SESSION_BUS_ADDRESS="" dropbox start

or

$ dropbox stop && dbus-launch dropbox start

How to ignore namespace when selcting XML nodes with XPath

I have several full article in PMC XML format to parse. I plan to use XPath. However, the namespace always breaks my path. For example, in the following XML I cannot use *//article-id to retrieve all article-id tags. Instead, I have to use *//{http://dtd.nlm.nih.gov/ns/archiving/2.3/}article-id. As you can see, it is really painful.

<?xml version="1.0" encoding="UTF-8"?><OAI-PMH
    xmlns="http://www.openarchives.org/OAI/2.0/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
    <responseDate>2016-04-08T01:08:52Z</responseDate>
    <request verb="GetRecord" identifier="oai:pubmedcentral.nih.gov:2702331" metadataPrefix="pmc">http://www.ncbi.nlm.nih.gov/oai/oai.cgi</request>
    <GetRecord>
        <record>
            <header>
                <identifier>oai:pubmedcentral.nih.gov:2702331</identifier>
                <datestamp>2009-06-27</datestamp>
                <setSpec>retrovir</setSpec>
                <setSpec>pmc-open</setSpec>
            </header>
            <metadata>
                <article xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://dtd.nlm.nih.gov/ns/archiving/2.3/" xsi:schemaLocation="http://dtd.nlm.nih.gov/ns/archiving/2.3/ http://dtd.nlm.nih.gov/archiving/2.3/xsd/archivearticle.xsd" article-type="research-article">
                      <front>
                        <article-meta>
                          <article-id pub-id-type="accession">PMC2702331</article-id>
                          <article-id pub-id-type="pmcid">PMC2702331</article-id>
                          <article-id pub-id-type="pmc-uid">2702331</article-id>
                          <article-id pub-id-type="publisher-id">1742-4690-6-47</article-id>
                          <article-id pub-id-type="pmid">19454010</article-id>
...

read more

How to return an subclass with generics

In 2013, I created a project to provide a general-purpose tree structure in Java.

One challenge at that time (mostly because I was not an expertise at that time, neither am I now) is the return type of Tree methods. For example, the return type of getChild(int index) that should return the child at the specified index.

read more

How to use Whatizit Web Services in Java

Whatizit is a text processing system that allows you to do textmining tasks on text. It is also available as a Web Service whose underlying idea is to ensure that software from various sources work well together. Whatizit is built on open standards of Simple Object Access Protocol (SOAP) and Web Services Description Language (WSDL). For the transport layer itself, Web Services uses most of the commonly available network protocols, especially Hypertext Transfer Protocol (HTTP). For more information on WSDL please refer to the W3C WSDL v1.1 Document.

read more

How to submit a package to PyPI

How to submit a package to PyPI

PyPI (Python Package Index) is a repository of software for the Python programming language. This article will tell you how to submit your package to PyPI, so others are able to install it with easy_install or pip. The offical document is at http://wiki.python.org/moin/CheeseShopTutorial#Submitting_Packages_to_the_Package_Index

Create your accounts

You must create accounts on PyPI Live and PyPI Test before upload your code.

After registration, create a pypirc configuration file at ~/. This file holds your information for authenticating with PyPI, both the live and the test versions.

[distutils]
index-servers =
  pypi
  pypitest

[pypi]
repository: https://pypi.python.org/pypi
username: {{your_username}}
password: {{your_password}}

[pypitest]
repository: https://testpypi.python.org/pypi
username: {{your_username}}
password: {{your_password}}

Prepare your package

Every package on PyPI needs to have a file called setup.py at the root of the directory. If you are using a markdown-formatted README file you’ll also need a setup.cfg file. Also, you’ll want a LICENSE.txt file describing what can be done with your code. So the directory structure would look like this:

root-dir/
  setup.py
  setup.cfg
  LICENSE.txt
  README.md
  mypackage/
    __init__.py
    file1.py
    file2.py
    file3.py

setup.py

This is metadata about your library.

from distutils.core import setup
setup(
  name = 'mypackage',
  packages = ['mypackage'],
  version = '0.1',
  description = 'A random test lib',
  author = 'Peter Downs',
  author_email = 'your email address',
  url = 'https://github.com/yfpeng/mypackage',
  keywords = ['testing', 'logging', 'example'],
  classifiers = [],
)

read more

How to create a Web Application Project with Java/Maven/Jetty

How to create a Web Application Project with Java/Maven/Jetty or Tomcat

In this article, we create a simple web application with the Maven Archetype plugin. We’ll run this web application in a Servlet container named Jetty, add some dependencies, write simple Servlets, and generate a WAR file. At the end of this article, you will also be able to deploy the service in Tomcat.

System requirements

Creating the Web Service Step by Step

This section explains how to create this simple web project from an EMPTY folder.

Creating the Simple Web Project

To create your web application

$ mvn archetype:generate -DgroupId=com.pengyifan.simpleweb \
      -DartifactId=simple-webapp \
      -Dpackage=com.pengyifan.simpleweb \
      -DarchetypeArtifactId=maven-archetype-webapp \
      -Dversion=1.0-SNAPSHOT \
      -DinteractiveMode=false

...
[INFO] BUILD SUCCESS

Once the Maven Archetype plugin creates the project, change the directory into the simple-webapp directory and take a look at the pom.xml. You should see the

<project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
  http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.pengyifan.simpleweb</groupId>
  <artifactId>simple-webapp</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>simple-webapp Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>simple-webapp</finalName>
  </build>
</project>

read more

How to collect Immutable Collection in Java

To begin with this story, let’s first have a look at how to creat a List from Stream in Java

List<String> sublist = list
  .stream()
  .filter(...)
  .collect(Collectors.toList());

This works perfectly fine but what if we want the list to be immutable? We could do this

List<String> immutableSubList = Collections.unmodifiableList(sublist);

or if we would like to use Guava ImmutableList, we could do

ImmutableList<String> immutableSubList = ImmutableList.copyOf(sublist);

However this is a bit awkward to use since the list will be copied one more time. If we want to do this in a lot of places throughout the code base, it is not fluid. Instead, what we want is

ImmutableList<String> sublist = list
  .stream()
  .filter(...)
  .collect(ImmutableCollectors.toList());

This post will discuss how to create the Collector of ImmutableList.

Collector

To create a Collector, we will use the static method of.

public static<t, A, R> Collector<T, A, R> of(
  Supplier<A> supplier,
  BiConsumer<A, T> accumulator,
  BinaryOperator<A> combiner,
  Function<A, R> finisher,
  Characteristics... characteristics);

read more

How to convert sourcecode to HTML, RTF, SVG, etc.

I am working on my paper which needs a piece of XML to syntax highlighted. I’ve found Sublime with “Copy as RTF” plugins is useful, but as a programmer I prefer something that being done via commend line, and more importantly being easily customizable.

So I did a some searches and came across highlight. To install it on Ubuntu is quite simple

sudo apt-get install highlight

Then I can use highlight to convert the XML file to RTF and copy it to the paper I am working on.

read more