# ifthen + [ngerman]babel + pgfplots + axis + text height = ☇

Continuing [ngerman]babel + pgfplots + axis + text height = ☇ and feeding

\RequirePackage{ifthen}
\newboolean{techrep}
\setboolean{techrep}{true}
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}\pgfplotsset{compat=1.14}
\usetikzlibrary{babel}
\begin{document}
\section{Section name}
\ifthenelse{\boolean{techrep}}{%
\begin{tikzpicture}\shorthandoff{"}
\begin{axis}[
xmax         = 5.5,
xmin         = 0,
ymax         = 5.5,
ymin         = 0,
extra x tick style = {text height=height("0")},
extra x ticks = 3
]
\end{axis}
\end{tikzpicture}%
}{}
\end{document}


(in a real example, there would be a lot of unrelated code around, which is all abstracted away here) to pdflatex, we obtain

! Missing number, treated as zero.
p
l.22 }{}

? X


Who is the culprit and what to do? Using the TikZ library babel doesn't help, neither does inserting \shorthandoff(") at various places (though, I've not tested ALL places).

• I think this post is very related. \begingroup\shorthandoff{"} \ifthenelse{\boolean{techrep}}{% \begin{tikzpicture} \begin{axis}[ xmax = 5.5, xmin = 0, ymax = 5.5, ymin = 0, extra x tick style = {text height=height("0")}, extra x ticks = 3 ] \end{axis} \end{tikzpicture}% }{}\endgroup works. – user194703 May 31 at 4:38
• @Schrödinger'scat Well, in a real example, inside the second argument of \ifthenelse there are pages of hardcore maths besides this tikzpicture. If it is possible to use " inside this argument... – user49915 May 31 at 4:42

This post is related. As far as I can see, the answers there provide only workarounds. Here is another workaround.

\RequirePackage{ifthen}
\documentclass{article}
\newboolean{techrep}
\setboolean{techrep}{true}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{babel}
\begin{document}
\section{Section name}
\begingroup\shorthandoff{"}
\ifthenelse{\boolean{techrep}}{%
\begin{tikzpicture}
\begin{axis}[
xmax         = 5.5,
xmin         = 0,
ymax         = 5.5,
ymin         = 0,
extra x tick style = {text height=height("0")},
extra x ticks = 3
]
\end{axis}
\end{tikzpicture}%
}{}\endgroup
\end{document}


I think that not using the ifthen package could be the best solution. If you load pgf, you can always introduce test integers and work with \ifnum or \ifcase, or a \newif.

\documentclass{article}
\newif\iftechrep
\techreptrue
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{babel}
\begin{document}
\section{Section name}
\iftechrep
\begin{tikzpicture}
\begin{axis}[
xmax         = 5.5,
xmin         = 0,
ymax         = 5.5,
ymin         = 0,
extra x tick style = {text height=height("0")},
extra x ticks = 3
]
\end{axis}
\end{tikzpicture}%
\else
\fi
\end{document}

• In my case, ifthen is a means of conditional compilation: the same set of latex sources is used to produce two documents: a main paper fitting into 35 pages and a technical report streching over 62 with all the details. – user49915 May 31 at 4:43
• @Just_A_Man But you could just use an \ifnum instead, can't you? – user194703 May 31 at 4:45
• I'd have to take a look at \ifnum, I've never used it. – user49915 May 31 at 4:48
• @Just_A_Man Internally the Boolean is just like a \newif. I added an example using such a built in Boolean. This has the great advantage that you can link it to the /.is if key handler from pgf. – user194703 May 31 at 4:51
• Using \iftechrep contents1 \else contents2 \fi has the disadvantage that during editing in emacs, there is no visual help (as there is for matching parentheses). But otherwise, it seems to be a good suggestion; thanks! – user49915 May 31 at 13:34

You might locally define active " to do what's expected by TikZ:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{ifthen}
\usepackage{pgfplots}\pgfplotsset{compat=1.14}
\usetikzlibrary{babel}

\newboolean{techrep}
\setboolean{techrep}{true}

\begin{document}
\section{Section name}
\ifthenelse{\boolean{techrep}}{%
\begin{tikzpicture}\edef"{\string"}
\begin{axis}[
xmax         = 5.5,
xmin         = 0,
ymax         = 5.5,
ymin         = 0,
extra x tick style = {text height=height("0")},
extra x ticks = 3
]
\end{axis}
\end{tikzpicture}%
}{}
\begin{tikzpicture}
\begin{axis}[
xmax         = 5.5,
xmin         = 0,
ymax         = 5.5,
ymin         = 0,
extra x tick style = {text height=height("0")},
extra x ticks = 3
]
\end{axis}
\end{tikzpicture}%
\end{document}


I have set twice the picture for comparison.

However, you can exploit the fact that \newboolean{techrep} is essentially the same as \newif\iftechrep.

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{ifthen}
\usepackage{pgfplots}\pgfplotsset{compat=1.14}
\usetikzlibrary{babel}

\newboolean{techrep}
\setboolean{techrep}{true}

\begin{document}
\section{Section name}
\iftechrep
\begin{tikzpicture}
\begin{axis}[
xmax         = 5.5,
xmin         = 0,
ymax         = 5.5,
ymin         = 0,
extra x tick style = {text height=height("0")},
extra x ticks = 3
]
\end{axis}
\end{tikzpicture}%
\fi
\end{document}

• Thanks! Is there a shorter way of writing \iftechrep\else elsepart \fi, i.e., omitting the then-part? Something like \if!techrep or \ifnottechrep? – user49915 May 31 at 13:43
• @Just_A_Man \unless\iftechrep? – egreg May 31 at 13:46
• Thx, \unless\iftechrep is prefect! It's not shorter than \iftechrep\else, though, but logically what we want to have. – user49915 May 31 at 13:52