LaTeX Tricks

2018-07-09

Bag of useful tricks of $\LaTeX$, you can preview all the examples in this post at https://www.overleaf.com/read/fzxqwbygfvmj.

# Useful tricks

## new or renew commands

Define new commands or renew existing commands. First, we define our \mypar command in the preamble:

\newcommand{\mypar}[1]{\noindent\textbf{#1}}
The \mypar command
1. adds vertical space on the top.
2. removes the indent at the beginning of the paragraph.
3. makes the text bold.

Then we can use the new command in our document.

\mypar{Evaluation}
The performance under the open-set protocol is evaluated in terms of [email protected] TAR and FAR are true accept rate' and false accept rate'.

Specifically, given several test images, we randomly sample several positive pairs where the two samples share the same identity, and negative pairs...

\mypar{Data Synthesizing.}
By default, the synthetic dataset contains 4,000 identities, and each identity has 100 samples...

The dimension of the synthetic image is $224\times 224$. The stroke width $w$ for principal lines and wrinkles are randomly selected from $1.5\sim 3$ and $0.5\sim 1.5$...

\mypar{Model Training.}
For our proposed method, we first pretrain models on synthesized data for 20 epochs and then finetune on real palmprint datasets.

The maximal learning rate for pretraining is 0.1 and 0.01 for finetune. All models are trained with mini-batch SGD algorithm.

Outcome:

## switch with \ifdefined statement

Some times we need multiple versions of the same manuscript. For example, when we submit a paper to a conference/journal, at the meantime we want to put it on arXiv. Due to the page limit of many conferences/journals, we may put more details in the arXiv version. In this case, we are not necessarily to prepare two separate latex documents, we can use the \ifdefined statement to turn on/off some of the content. Below is an example of using \ifdefined to turn on the appendix if the manuscript is prepared for arXiv.

\newcommand{\arXiv}{} % define the arXiv command here
\ifdefined\arXiv
\appendix
Some detailed content in the appendix ...
\else
% nothing here
\fi


With above codes, we can conveniently turn on/off the appendix by adding or removing the \newcommand{\arXiv}{} command. We can also switch between normal and anonymous submisions:

\ifdefined\arXiv
\author{Albert Einstein}
\else
\author{Anonymous authors}
\fi


# Useful packages

## xcolor: define customized colors

xcolor defines customized colors using ether rgb values:

\usepackage{xcolor}
\definecolor{americanrose}{rgb}{1.0, 0.01, 0.24}
\definecolor{myred}{rgb}{0.753, 0.314, 0.275}
\definecolor{myblue}{rgb}{0.0, 0.24, 0.95}

or hex codes：
\definecolor{orange}{HTML}{FF7F00}


## overpic: put text on figures

overpic enables you to put text on figures at arbitary positions. You can put regular text, equations, references and whatever element you want on figures at any position at will. Just replace \includegraphics with \begin{overpic}...\end{overpic} and then put text in between.

Here is an example use case of overpic.

\begin{figure}[!htb]
\centering
\begin{overpic}[width=0.5\linewidth]{example-image-a}
\put(5, 5){a}
\put(5, 15){reference to~\cite{lamport94}}
\put(5, 25){\cref{sec:tricks}}
\put(5, 35){{\color{blue1}{colored text}}}
\put(5, 45){{\color{yellow1}{colored text}}}
\put(5, 55){$f(x) = \int x^2dx$}
\end{overpic}
\caption{Example image A}
\label{fig:example-a}
\end{figure}

The \put(x, y){xx} command is used to place text on figure, x, y are the coordinates of the text to be placed and xxx is the content to be placed. The outcome is as below:

% define colors
\usepackage{xcolor}
\definecolor{americanrose}{rgb}{1.0, 0.01, 0.24}
\definecolor{myred}{rgb}{0.753, 0.314, 0.275}
\definecolor{myblue}{rgb}{0.0, 0.24, 0.95}
% set colors for lins and references
\usepackage[pagebackref]{hyperref}
\hypersetup{
citecolor=myred,
citecolor=myblue,
urlcolor=myblue
}


## cleveref: automatically cite figures/tables/sections

First, import cleveref in the preamble. Note that we should place\usepackage[capitalize]{cleveref} after \usepackage{hyperref}.

\usepackage[capitalize]{cleveref}
\crefname{section}{Sec.}{Secs.}
\crefname{table}{Tab.}{Tabs.}
\crefname{figure}{Fig.}{Figs.}

\begin{document}
% refer to tables/figures/sections with a unified command
As illustrated in~\cref{xxx}. % a reference to a figure
The numbers in~\cref{xxx}. % a reference to a table
\end{document}

Then, simply use \cref{xxx} for figures/tables/sections and the packages will automatically adds Fig./Tab./Sec. prefixes according to the content.

Many templates require the authors' orcid information. For example, the ECCV $\LaTeX$ template requires the orcid of all authors and provides the \orcidlink command to insert the orcid digital ID. But the digital ID is too long and doesn't look as nice as the orcid icon. Below is the author area with digital orcid:
The orcidlink package provides a simple command \orcidlink to insert orcid icons with hyperlink to the orcid webpage. If you are using the ECCV template, only two line of codes can replace the original digital ID with clickable icon:
\usepackage{orcidlink}