4

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.
<to be read again> 
                   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).

  • 1
    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. –  May 31 '20 at 04:38

2 Answers2

2

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}
  • 1
    @Just_A_Man But you could just use an \ifnum instead, can't you? –  May 31 '20 at 04:45
  • 2
    @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. –  May 31 '20 at 04:51
1

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.

enter image description here

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}
egreg
  • 1,121,712