• Maryam Daryalal

# LaTeX Tips

Updated: Jan 28

## I will keep this post updated with LaTeX tips I learn along the way.

When deadlines are looming, nothing is more frustrating than fixing that fractional value at the second column of the tenth row of a table in a LaTeX document! LaTeX is beautiful and a joy to work with, but some tricks here and there can make it even more pleasant.

### Tables

Excel2LATEX

My go to solution for fast table manipulation is Excel2LATEX. This is an Excel macro for exporting tables from Excel and converting them to LaTeX code. It's powerful and often precise, although you might still need to do some tweaks yourself to get exactly what you need if the table format is complicated. It supports column and row merges as well as table stylizing operations.

TableConvert

In case you don't have access to Excel, you can use TableConvert which is an online conversion tool that works with various languages, including LaTeX. It doesn't seem to be as versatile as Excel2LATEX in terms of functionality, but it's an easy to use tool for quick generation of rows and columns of a simple table.

### Vector Graphics

The following are tools for easy generation and manipulation of figures to be used in LaTeX documents. They both make drawing complicated figures a breeze, however I believe it is still very useful to understand the code and know how to edit it for quick fixes.

TikZ

Recently I've been using mathcha for drawing my figures in an editor and it generates the TikZ code. Then the code can be simply copy and pasted in the figure environment. It can also import the codes that are already generated, so the editing becomes easier.

Among the similar tools, the feature that I like about matchcha is that it provides you with an account where your drawings are stored on the cloud, so you can always have access to them. Furthermore, you can define projects and organize the drawings. Many other tools that I've tried so far have been laggy and difficult to work with. But mathcha is fast and smooth, like overleaf smooth! And it's completely free.

PSTricks

LaTeXDraw is an editor for drawing figures. It can directly generate a pdf file of your figure, as well as the PSTricks code. It's come a long way and has improved in all aspects. It can be installed on all common platforms and is well-painted with regular updates and fixes.

### Appendix and e-Companion

So you're done writing the paper and now you want to submit the main text and its online supplements (e-companion) to the journal, and put it up at arXiv and/or optimization-online. When I was submitting for the first time, I encountered some issues when it came to the hyperlinks between the main text and it appendix\e-companion. I'll explain my solutions here.

e-Companion as a Separate Document

Many journals (e.g., IJOC) require you to submit the main document and the online supplements as separate documents. However, by doing this, the hyperlinks between the main document and the e-companion breaks. Here I have a quick fix (and in general, how to set up hyperlinks between two separate documents).

Assume that you have two documents A.tex and B.tex (in the same folder), and you have references between the two, i.e., A.tex has a command of the form \ref{ref_in_B} where ref_in_B is a label defined in B.tex, and B.tex uses \ref{ref_in_A}, with ref_in_A a label defined in A.tex. Then, in the header of A.tex, right before \begin{document}, add the following lines:

\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument{B}

Note the order of the call to the packages: First xr-hyper, then hyperref. In general, hyperref should always be the last package to be called. In the header of B.tex also, add the following:

\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument{A}

To establish the hyperlinks, compile the files (with either pdfLaTeX or XeLaTeX) in the following order A.tex -> B.tex -> A.tex -> B.tex. Now if you have both pdf files in the same folder, once you click on one hyperlink in A.pdf that points to an object in B.pdf, the B.pdf file is opened and shows you the correct place. I have to mention two things here:

• This doesn't work on overleaf. So if you're working on overleaf, for the final submission you need to use a local TeX distribution and compile on your own machine.

• If on your machine the files are on a directory that needs permission for modification, you'll get an error when you click on the hyperlinks. Simply open both files yourself and the hyperlinks should still work.

Appendix in the Same File

This one is easy and should work right away. But still sometimes the hyperlinks in the main document that reference to the Appendix objects do not point to the right place. For example, assume that you are referencing Section A of the Appendix in the main text. It often happens that if you click on A, you are just directed to Section 1 of the main text! There are a couple of workarounds for this. But the easiest one for me is to simply include the appendix package:

\usepackage[toc,page]{appendix}

Now if I include an Appendix.tex file using the the following command:

\begin{appendices}
\input{./Appendix}
\end{appendices}

and compile the main text, all hyperlinks work perfectly.

See All