13

This code works correctly:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}

\begin{tikzpicture}
  \tikzset{
    every picture/.prefix style={
      execute at begin picture=\shorthandoff{;}
    }
  }
  \def\names{{"1", "2"}}
  \foreach \i in {0,1} {%
    \ifnum\i=0\relax
      \node (\i) [draw] {\pgfmathparse{\names[\i]}\pgfmathresult};
    \else
      \pgfmathparse{int(\i-1)}
      \node (\i) [draw,right= 1cm of \pgfmathresult]
            {\pgfmathparse{\names[\i]}\pgfmathresult};
      \draw[dotted] ($(\pgfmathresult.south east) !.5! (\i.south west)$)
            -- +(0,1cm);
  \fi
}
\end{tikzpicture}
\end{document}

But when I add

\usepackage[utf8]{inputenc}
\usepackage[german]{babel}

to the preamble, it starts giving an error:

! Argument of \language@active@arg" has an extra }.
<inserted text> 
                \par 
l.25 }

the same for russian. It is somehow related to the quotes in the array:

\def\names{{"1", "2"}}

I tried the tricks, shown here for the french, but they don't work.

12

The trick for French disables the shorthand ;, which isn't used with German, where the shorthand to be disabled is ".

However, the \tikzset{every picture/...} command should be given outside the picture, or it won't have effect.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\tikzset{
  every picture/.prefix style={
    execute at begin picture=\shorthandoff{"}
  }
}

\begin{document}

\begin{tikzpicture}
  \def\names{{"1", "2"}}
  \foreach \i in {0,1} {%
    \ifnum\i=0\relax
      \node (\i) [draw] {\pgfmathparse{\names[\i]}\pgfmathresult};
    \else
      \pgfmathparse{int(\i-1)}
      \node (\i) [draw,right= 1cm of \pgfmathresult]
            {\pgfmathparse{\names[\i]}\pgfmathresult};
      \draw[dotted] ($(\pgfmathresult.south east) !.5! (\i.south west)$)
            -- +(0,1cm);
  \fi
}
\end{tikzpicture}
\end{document}
6

\usetikzlibrary{babel} helps in this case to support active quotes:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{tikz}
\usetikzlibrary{babel,positioning,calc}
\begin{document}

\begin{tikzpicture}
  \tikzset{
    every picture/.prefix style={
      execute at begin picture=\shorthandoff{;}
    }
  }  
  \def\names{{"1", "2"}}
  \foreach \i in {0,1} {%
    \ifnum\i=0\relax
      \node (\i) [draw] {\pgfmathparse{\names[\i]}\pgfmathresult};
    \else
      \pgfmathparse{int(\i-1)}
      \node (\i) [draw,right= 1cm of \pgfmathresult]
            {\pgfmathparse{\names[\i]}\pgfmathresult};
      \draw[dotted] ($(\pgfmathresult.south east) !.5! (\i.south west)$)
            -- +(0,1cm);
  \fi
}
\end{tikzpicture}
\end{document}

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.