Create multiple pdf files from same tex file - latex

I have multiple data files (result_a.csv, result_b.csv, ..) and I want to create plot for each one (result_a.pdf, result_b.pdf - or similar). The plot is the same but the input file is different and the output file is different. Is there a way I can run a loop, pass the parameter names from the outside and save the output with a distinctive name?
Assume that my code for creating the plot -
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{ytick style={draw=none}, xtick style={draw=none}}
\usetikzlibrary{patterns}
\newcommand\param{a}
\begin{document}
\begin{tikzpicture}
\footnotesize
\begin{semilogxaxis}
\addplot[color=red,mark=triangle] table [x=x,y=y,col sep=comma, mark=*] {result_\param.csv};
\end{semilogxaxis}
\end{tikzpicture}
\end{document}

Assuming your file is called document.tex, you can pass the name of the csv file to the document by compiling with the following command
pdflatex -jobname="document-b" "\\newcommand*\\version{b}\\input{document}"
and the document:
\documentclass[tikz]{standalone}
% setting a default value in case it is compiled without the newcommand
\unless\ifdefined\version
\def\version{a}
\fi
\usepackage{pgfplots}
\pgfplotsset{ytick style={draw=none}, xtick style={draw=none}}
\usetikzlibrary{patterns}
\newcommand\param{a}
\begin{document}
\begin{tikzpicture}
\footnotesize
\begin{semilogxaxis}
\addplot[color=red,mark=triangle] table [x=x,y=y,col sep=comma, mark=*] {result_\version.csv};
\end{semilogxaxis}
\end{tikzpicture}
\end{document}

If you are working under a Linux Distro or under a Mac OS, you may use a shell script.
Let init.tex be the tex file with
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{ytick style={draw=none}, xtick style={draw=none}}
\usetikzlibrary{patterns}
\newcommand\param{a}
\begin{document}
\begin{tikzpicture}
\footnotesize
\begin{semilogxaxis}
\addplot[color=red,mark=triangle] table [x=x,y=y,col sep=comma, mark=*] {
and let ends.tex be the file containing
};
\end{semilogxaxis}
\end{tikzpicture}
The following script reads each .csv file, puts its contents in a tex file organized as follows:
init.tex
result_x.csv
ends.tex
produces the tex file result_xx.tex and compiles it, providing the file result_xx.pdf
#!/bin/bash
for i in $(ls *.csv)
do
a=$(basename -s .csv $i)
cp init.tex $a.tex
echo $i >> $a.tex
cat ends.tex >> $a.tex
pdflatex $a.tex
done
It is a naive solution, there are more experienced than me bash--script writers here in SO, but it should work.
PS. Remember to make the script executable to make it work:
chmod 755 myscript.sh
See for example here.

Related

How do I send the result of \pgfkeys to Lua?

In the example below the macro "\pgfkeysprintvalue" is a variant of "\pgfkeysgetvalue" that sort of sends the value of a key to Lua, and prints it from Lua:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfkeyssetvalue{/p}{PP}
\pgfkeysgetvalue{/p}{\luatmp}
\luatmp % prints a "PP" in the document
\def\pgfkeysprintvalue#1{
\pgfkeysgetvalue{#1}{\luatmp}
\directlua{print("#1: "..(token.get_meaning("luatmp") or ""))}
}
\pgfkeyssetvalue {/q}{QQ}
\pgfkeysprintvalue{/q} % prints "/q: ->QQ" on stdout
\end{document}
In this other example the first three "\pgfkeys"s have interesting side-effects but expand to nothing, and the "\pgfkeys{/c,/d,/e=DD}" expands to "(c)(d:)(c)(d:DD)":
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfkeys{/c/.code=(c)}
\pgfkeys{/d/.code=(d:#1)}
\pgfkeys{/e/.style={/c,/d=#1}}
\pgfkeys{/c,/d,/e=DD}
\end{document}
The last "\pgfkeys" above "prints" the "(c)(d:)(c)(d:DD)" into the document, and it appears in the PDF.
How do I write a variant of \pgfkeys - let me call it \pgfkeysprint - that would store the expansion of its argument in a macro called \luatmp? I guess that it would be like this:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\def\pgfkeysprint#1{
<I don't know what to put here>{#1}{\luatmp}
\directlua{print("#1: "..(token.get_meaning("luatmp") or ""))}
}
\pgfkeys{/c/.code=(c)}
\pgfkeys{/d/.code=(d:#1)}
\pgfkeys{/e/.style={/c,/d=#1}}
\pgfkeysprint{/c,/d,/e=DD} % prints "/c,/d,/e=DD: -> (c)(d:)(c)(d:DD)" on stdout
\end{document}
I'm trying to write functions for inspecting PGF keys from a Lua REPL running inside LuaLaTeX, and the part corresponing to the "<I don't know what to put here>" above is the main piece that is still missing...
Obs: I tried to write my macro \pgfkeysprint by adapting the definition of \pgfkeysgetvalue in pgf/utilities/pgfkeys.code.tex, but I couldn't find the right way to use the "\expandafter"s...

How to prefix a refence in LaTex?

so I have figures like this:
\begin{figure}[h]{}
\includegraphics[width=\textwidth]{./assets/demo/identify-usecases/DomainSplitt-1.jpg}
\caption{Identifying Domains: Match History with Filter}
\centering
\label{fig:domainsplitt-one}
\end{figure}
and I reference them like this: \ref{fig:domainsplitt-one}.
In the generated PFD, the images have the caption like this Figure 4.13: Identifying Domains: Match History with Filter. But the reference in the text only has the number 4.13.
I have something similar for code:
\begin{code}
\captionof{listing}{Custom Element listening to global custom events}
\label{code:listening-custom-event}
\begin{minted}{JavaScript}
Here, the code has the prefix Source Code but in the reference is only the number. The rule I use for this is
\usepackage[newfloat]{minted}
\usepackage{caption}
\newenvironment{code}{\captionsetup{type=listing}}{}
\SetupFloatingEnvironment{listing}{name=Source Code}
So what I need is, that the reference also have this prefix in the text. Since I'm really new to latex may question is: How do I do this?
edit: here is a link with a replica:
https://github.com/adrian-goe/latex-replica
The cleveref package will do all the work for you:
% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}
% Preamble
%\documentclass[11pt]{article}
% Packages
\documentclass[12pt,DIV12,BCOR0mm,twoside,openright,headings=normal, numbers=noenddot,headsepline,headinclude]{scrreprt}
\usepackage[automark,headsepline]{scrlayer-scrpage}
\usepackage{scrhack} % to avoid KOMA-Script warning
\usepackage[utf8]{inputenc} % UTF8 encoding
\usepackage[T1]{fontenc}
\usepackage{txfonts} % Postscript fonts
\usepackage[ngerman,english]{babel}
\usepackage[style=numeric-comp,giveninits=true,maxnames=10,sorting=none]{biblatex}
\usepackage{graphicx}
\usepackage[usenames]{xcolor}
\usepackage[pdftex]{hyperref}
\usepackage{wallpaper}
\usepackage[newfloat]{minted}
\usepackage{caption}
\newenvironment{code}{\captionsetup{type=listing}}{}
\SetupFloatingEnvironment{listing}{name=Code}
\usemintedstyle{manni}
\usepackage[noabbrev]{cleveref}
\crefname{listing}{code}{code}
\Crefname{listing}{Code}{Code}
% Document
\begin{document}
this is my sample text and i want to reference \cref{code:update-a-attribute} and the \cref{fig:image}
\begin{figure}[h]{}
\includegraphics[width=\textwidth]{./img.png}
\caption{some image}
\centering
\label{fig:image}
\end{figure}
\begin{code}
\captionof{listing}{Update a Attribute}
\label{code:update-a-attribute}
\begin{minted}{JavaScript}
const fragment = document.querySelector(".fragment");
fragment.setAttribute("data", 2)
\end{minted}
\end{code}
\end{document}
(please note that you can only have one single documentclass)

Undefined references using pagesel in Latex

Let's say I have some labels in a part of the document that I exclude using pagesel. However, I want to reference them in the part that I am including. How is that possible?
Below is a minimum example which should print "This is reference 1", but instead prints "This is reference ??".
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[files,2-]{pagesel}
\title{Pagesel problem}
\begin{document}
\maketitle
\section{Introduction}
This is label \label{ref:label1}.
\cleardoublepage
This is reference \ref{ref:label1}
\end{document}
You can retain the labels from pages not shown by first compiling your whole document without the pagesel package and then, in a second step, use the pagesel package with the default nofile option:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[
%files,
2-]{pagesel}
\title{Pagesel problem}
\begin{document}
\maketitle
\section{Introduction}
This is label \label{ref:label1}.
\cleardoublepage
This is reference \ref{ref:label1}
\end{document}
Other possible approach: compile the complete document and then use a tool like pdftk to extract the pages you like.

How can I mention the name of a LaTeX command in my beamer presentation?

I am preparing a presentation in beamer with gradientframe package. But it's giving me an error.
How can I write the name of the command in \frame?
\begin{frame}
\frametitle{Introduction}
The gradientframe package provides a command, \gradientframe for simple and discreet
rectangular grayscale gradient frames around objects, such as figures or tables, to set
them apart from the surrounding text.
\end{frame}
As in several answers to the linked question (thanks #Bas Swinckels), the way advised to insert a backslash \ in the output is to use \textbackslash in the source.
Then, you can use (or not) just \texttt{} (rather than verbatim or else) to mark command names.
Finally, if you have to mention these command name(s) many times in your slides, you may want to put the above two in a newcommand:
\documentclass{beamer}
\newcommand{\mycomm}[1]{\texttt{\textbackslash #1}}
%\newcommand{\commgf}{\texttt{\textbackslash gradientframe}}
\begin{document}
\begin{frame}
\frametitle{Introduction}
... a command, \textbackslash gradientframe for simple ...
or:
... a command, \texttt{\textbackslash gradientframe} for simple ...
or, better:
... a command, \mycomm{gradientframe} for simple ...
%... a command, \commgf{} for simple ...
\end{frame}
\end{document}
This code gives you:

gnuplot with texshop in osx

I have installed gnuplot through macports but when i compile my latex document in texshop it doesn't show the plots and I get these errors in the log file:
Package pgf Warning: Plot data file `tutorial.x.table' not found. on input line
17.
Package pgf Warning: Plot data file `tutorial.sin.table' not found. on input li
ne 19.
Package pgf Warning: Plot data file `tutorial.exp.table' not found. on input li
ne 21.
I'm just trying to compile this basic example:
% Author: Till Tantau
% Source: The PGF/TikZ manual
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
% GNUPLOT required
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[domain=0:4]
\draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9);
\draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};
\draw[color=red] plot[id=x] function{x}
node[right] {$f(x) =x$};
\draw[color=blue] plot[id=sin] function{sin(x)}
node[right] {$f(x) = \sin x$};
\draw[color=orange] plot[id=exp] function{0.05*exp(x)}
node[right] {$f(x) = \frac{1}{20} \mathrm e^x$};
\end{tikzpicture}
\end{document}
Yes, you need to turn the .gnuplot files that tikz creates into the tables files. You have two choices for this:
you can run (pdf)latex with the additional command line switch --shell-escape, sometimes also called --enable-write-18, then gnuplot is run automatically for you. (You might not be comfortable with allowing arbitrary programs to be starte from within pdflatex, though.)
you can run gnuplot yourself on the test.exp.gnuplot, test.sin.gnuplot, test.x.gnuplot etc. files. Simply gnuplot test.exp.gnuplot should do it. (Can't verify here, since my gnuplot version is too old.)

Resources