TikZ format and submitting papers

Normally, the procedure of including figures consist of generating a .Fig from your programing language, generating a .eps or .pdf and then including it in your TeX. There is two essential problems with this scheme. The first one is that if you have to make small changes in the plot, you need to go back to your .Fig file and regenerate the output format again. The second problem comes from the type font utilized in the plot. If the plot aspect ratio is changed, chances are the font is also going to change.

A solution for this problem is using the package TikZ. TikZ is a TeX package for creating graphics. If you happen to use MatLab as your programming language to generate your plots a very useful script can be use to generate your plot in the TikZ format by invoking:

matlab2tikz('figure.tikz');

The following commands are needed in the LaTeX file:

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}

And in the document itself:

\begin{figure}[!h]
    \subfloat[\label{fig:figure1}]{%
        \input{fig/figure1.tikz}
    }
    \hfill
    \subfloat[\label{fig:figure2}]{%
        \input{fig/figure2.tikz}
    }
    \caption{This is the caption.}
    \label{fig:label}
\end{figure}

Now, I had some problems with large size images. MikTeX has a limit of memory usage, and for some heavy TikZ files this limit can cause errors. The follow procedure can be use to extend memory limits in MikTeX.

In Windows prompt, write:

initexmf --edit-config-file=pdflatex

An editor will open, then write the following lines and save it:

main_memory=6000000 
extra_mem_bot=3000000 
font_mem_size=3000000 
pool_size=3000000 
buf_size=3000000

Afterwards call initexmf --dump=pdflatex.

Subimitting a paper to journals

After your paper is done and you are happy with your high quality images you decide to submit your paper for publication. The problem is that many journals do not accept the TikZ format (yet?). Two options arises. Go back to square one and redo all images the old fashion way. Or like I did, do research for a whole day to find a workaround method.

Fortunately, there is a neat way of converting your TikZ images to pdf maintaining the quality. The method consist of using the external library.

Add the following lines to you TeX file:

\usetikzlibrary{external} %this one export the plot as a pdf
\tikzexternalize[prefix=figures/] %to this path
\tikzexternalize % activate the external library

Externalization relies on ‘shell escape’. When this is restricted or disabled, sometimes externalization can’t work because it requires the compiler to spawn additional compilation commands in order to create each picture separately. By default, this feature is disabled for security reasons. A restricted set of commands may be spawned, but this set is not sufficient for the compilation of the pictures. Hence, you need to override the default setting by explicitly allowing unrestricted shell escape for the compilation. In TeXstudio configuration -> command tab look for the pdflatex line and add to the end:

-shell-escape

Mansour.

comments powered by Disqus