LaTeX-tips

sHere I introduce some useful TeX-tips to write research articles using LaTeX on Mac OS X.

I assume that:

  1. TeX Live is installed;
  2. Readers have some knowledge on how to write a preamble, equations, how to section, how to use .bib files; i.e. basic structure of .tex files.
  3. Readers are interested in LaTeX, but not LuaTeX,

How to view package documentations

On Terminal, issuing

texdoc XX

where XX is a package name, allows you to view a package documentation in PDF. For instance,

texdoc txfonts

will show you the txfonts-package documentation if available.

How to find locations of files in TeXLive

Sometimes you may want to know the address of a certain package or more generally a certain file which is supposed to be somewhere in TeXLive. To this purpose, issuing

kpsewhich XX

on Terminal will tell you the address of a file XX. For instance, in my current system,

kpsewhich cleveref.sty

returned me:

/usr/local/texlive/2016/texmf-dist/tex/latex/cleveref/cleveref.sty

What is fontenc?

fontenc is a font encoding. Without using fontenc, PDF might not produce a correct output (e.g. you may not copy-paste sentences from such a PDF), hyphenation becomes poor, etc. Hence issuing the following is strongly recommended:

\usepackage[T1]{fontenc}

as a magical charm. Also, \usepackage{textcomp} is highly recommended.

Reply letter

I found one fantastic example to create a sophisticated reply letter:
http://tex.stackexchange.com/questions/174833/running-numbers-for-comments/174834

I found someone else was doing a fantastic job to link Reply letter and Main document, but it might sound too complex or too elaborated to be practical.

One number in paralleled equations

When use align environment, all the lines are numbered. To prevent this,
instead one can use:

\begin{equation}
\begin{split}
E &= m c^{2},\\
T &= 2\pi \sqrt{\frac{m}{k}}
\end{split}
\end{equation}

which gives a single number to a set of equations.

Reference manager

I use BibDesk , which is of course (1) free, (2) very light, and (3) allowing automatic importation from a PDF. I am fully happy with BibDesk, but other options are: Mendeley, JabRef, etc. Usage can be easily found online. Key is to compile (at least) 4 times (if we use pdfplatex) to produce (1) aux, (2) bil, (3) ref list, and (4) inline citations.

Dividing a document into multiple files and editing

Personally I prefer to divide documents into multiple .tex files. For instance, issuing \input{ryosuke} allows for a inclusion of ryosuke.tex in a main document.

However, division of document incurs a large cost in terms of searching, replacing and editing phrases (e.g. when we want to convert a term “self-fertilization” to “selfing”, we have to do replacement in all the .tex files).

In Mac OS X (which of course is based on UNIX… and UNIX was developed in Berkeley!), the following UNIX code allows to change a specific word “A” to “B” across files in a same directory:

grep -l 'A' ./*.tex | xargs sed -i.bak -e 's/A/B/g'

Please make sure to use this command in your working directory of .tex files. Otherwise, terrible issues can occur. I’d move all the .tex files into a temporary directory (after issuing, say, mkdir temp), and then issue the above command.

NB: In the above code, * indicates a wildcard, so that all the .tex files in the directory is subject to the command.

Do not write your affiliation separately

It is of incredible help to allow for automatic description of your affiliation — even a post-doc (like me), his/her affiliation would be relatively temporally stable.

I make a style file with the text:

\newcommand{\authorinfo}
{\begin{enumerate}
\item Department of Biology, Faculty of Sciences, Kyushu University, Fukuoka, Japan.
\item Biosciences, University of Exeter, Cornwall Campus, Penryn, Cornwall TR10 9EZ, United Kingdom.
\item Department of Integrative Biology, University of California, Berkeley, CA 94720, United States.
\item ORCID ID: 0000-0002-2396-1109 \texttt{http://orcid.org/0000-0002-2396-1109}
\end{enumerate}}

and place it in a presumably stable, local directory. Issue the ln -s command in UNIX to make a symbolic link in a proper location at TeXlive (environment-dependent).

If you want to produce your affiliation in an itemization way, you could just type \authorinfo in your .tex file… so voila! Get your affiliation shown automatically. No typo is possible once it is typed correctly.

広告