I would like to declare functions in tikz for multiple uses of the same function within the code.
Sadly, it seems that the tikz "declare function" is not compatible with the french option in babel.
Indeed, the following code (that I simplifed on purpose) runs fine :
\documentclass[english]{article}
\usepackage{babel}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\tikzset{declare function={Carre(\t)=\t*\t;}}
\draw plot [domain=-1:1] (\x,{Carre(\x)});
\end{tikzpicture}
\end{document}
But when I replace
\documentclass[english]{article}
with
\documentclass[english,french]{article}
compilation generates an error. This is what the log file says :
Missing character: There is no = in font nullfont!
Missing character: There is no @ in font nullfont!
Missing character: There is no @ in font nullfont!Runaway argument?
-1:1] (\x ,{Carre(\x )}); \end {tikzpicture} \end {document}
! Paragraph ended before \pgfmath@local@@functions was complete.\par
l.18I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
Before posting this, I updated all packages without success.
Any help welcome!
Best Answer
The semicolon is made active by the french
babel
option, which throws the TikZ parser off. You can say\shorthandoff{;}
in yourtizpicture
to fix this.You can do this either by manually putting
\shorthandoff{;}
at the start of eachtikzpicture
, or you can use a TikZ style for inserting the code automatically into eachtikzpicture
by settingor, as Tobi points out in a comment, you can load the
etoolbox
package and useto patch the
tikzpicture
environment.