6

This question is a build-up on the "classical" Problem with babel and tikz using \draw; it is known that the babel package, in some language, make ><' actives and wreak havoc with tikzpicture environment.

The new (3.0+) tikz has a solution as a package named babel; it works a treat almost everytime --- unless you use it in this MNWE:

\documentclass[]{article}
\usepackage[spanish]{babel}
\usepackage{tikz}
\usepackage{ifthen}

\usetikzlibrary{babel} % this works most of the time, but not in
                       % an \ifthenelse 
\newboolean{solution} \setboolean{solution}{true} 

\begin{document}

\ifthenelse{\boolean{solution}}{

    \begin{tikzpicture}[]
        \draw [thin, ->] (-1,0)  -- (0,0);
    \end{tikzpicture}

 }% end \ifthenelse{\boolean{solution}}{
{
% not solution here 
}

\end{document}

which will fail with the infamous

Paragraph ended before \language@active@arg> was complete.

Now, the classical solution of avoid active characters in babel will work (and it is arguably the right one, thanks to unicode and utf-8 ubiquity), so just using

 \usepackage[spanish,es-noquoting]{babel}

will solve the thing. Anyway, is this an expected behavior? Is it possible fix \usetikzlibrary{babel} to work around this problem? And if not, is there a macro to obtain the same effect of the es-noquoting option after the fact, so I can correct a previous call of babel in a random class/package?

  • 1
    You can put \deactivatequoting anywhere in you preamble or document, to turn off the special meaning of < and >. – JLDiaz Jun 15 '16 at 13:52
  • Not related with your question but, may be, with your code: tex.stackexchange.com/q/266117/1952, tex.stackexchange.com/questions/101479/… – Ignasi Jun 15 '16 at 13:58
  • Tikz library babel only sets a couple of tikz which instruct tikz to deal appropiately with special chars in the context of tikz nodes and paths, but probably ifthen package contains some kind of scantokens which reads the argument when the special chars are still active, so tikz has no chance to apply its wizardry – JLDiaz Jun 15 '16 at 14:04
  • A (stupíd) workaround is to just switch languages for the offending stretch (here the whole tikzpicture). – vonbrand Apr 12 at 17:26
2

I don't know exactly what is happening but ifthen is interfering here. If I replace with a simple if-macro it works without any problems

\documentclass[]{article}
\usepackage[spanish]{babel}
\usepackage{tikz}

\usetikzlibrary{babel} % this works most of the time, but not in
                       % an \ifthenelse 
\newif\ifboolsolution
\boolsolutiontrue

\begin{document}

\ifboolsolution%
    \begin{tikzpicture}[]
        \draw [thin, ->] (-1,0)  -- (0,0);
    \end{tikzpicture}
\else%
%
\fi%
\end{document}

with the package list

 *File List*
 article.cls    2014/09/29 v1.4h Standard LaTeX document class
  size10.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
   babel.sty    2016/02/24 3.9q The Babel package
 spanish.ldf
    tikz.sty    2015/08/07 v3.0.1a (rcs-revision 1.151)
     pgf.sty    2015/08/07 v3.0.1a (rcs-revision 1.15)
  pgfrcs.sty    2015/08/07 v3.0.1a (rcs-revision 1.31)
everyshi.sty    2001/05/15 v3.00 EveryShipout Package (MS)
  pgfrcs.code.tex
 pgfcore.sty    2010/04/11 v3.0.1a (rcs-revision 1.7)
graphicx.sty    2014/10/28 v1.0g Enhanced LaTeX Graphics (DPC,SPQR)
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
graphics.sty    2016/01/03 v1.0q Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    2016/01/03 v1.10 sin cos tan (DPC)
graphics.cfg    2010/04/23 v1.9 graphics configuration of TeX Live
  pdftex.def    2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/error messages (HO)
 ltxcmds.sty    2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
  pgfsys.sty    2014/07/09 v3.0.1a (rcs-revision 1.48)
  pgfsys.code.tex
pgfsyssoftpath.code.tex    2013/09/09  (rcs-revision 1.9)
pgfsysprotocol.code.tex    2006/10/16  (rcs-revision 1.4)
  xcolor.sty    2007/01/21 v2.11 LaTeX color extensions (UK)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
 pgfcore.code.tex
pgfcomp-version-0-65.sty    2007/07/03 v3.0.1a (rcs-revision 1.7)
pgfcomp-version-1-18.sty    2007/07/23 v3.0.1a (rcs-revision 1.1)
  pgffor.sty    2013/12/13 v3.0.1a (rcs-revision 1.25)
 pgfkeys.sty    
 pgfkeys.code.tex
 pgfmath.sty    
 pgfmath.code.tex
  pgffor.code.tex
    tikz.code.tex
supp-pdf.mkii
pdftexcmds.sty    2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO)
ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
   ifpdf.sty    2011/01/30 v2.3 Provides the ifpdf switch (HO)
epstopdf-base.sty    2010/02/09 v2.5 Base part for package epstopdf
  grfext.sty    2010/08/19 v1.1 Manage graphics extensions (HO)
kvdefinekeys.sty    2011/04/07 v1.3 Define keys (HO)
kvoptions.sty    2011/06/30 v3.11 Key value format for package options (HO)
kvsetkeys.sty    2012/04/25 v1.16 Key value parser (HO)
etexcmds.sty    2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)
epstopdf-sys.cfg    2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
6

The problem is that when the tikzpicture is in the argument to another command, the category codes are frozen and the trick used by the babel library no more works.

The (admittedly not so nice) workaround is to disable the quoting feature of babel-spanish, that is not so important now that csquotes can do the same service in a cleaner way.

\documentclass[]{article}
\usepackage[spanish,es-noquoting]{babel}
\usepackage{tikz}
\usepackage{ifthen}

\usetikzlibrary{babel} % this works most of the time, but not in
                       % an \ifthenelse 
\newboolean{solution} \setboolean{solution}{true} 

\begin{document}

\ifthenelse{\boolean{solution}}{%
    \begin{tikzpicture}[]
        \draw [thin, ->] (-1,0)  -- (0,0);
    \end{tikzpicture}%
 }% end \ifthenelse{\boolean{solution}}{
{%
% not solution here 
}

\end{document}

This problem is not limited to \ifthenelse; if I define

\newcommand{\foo}[1]{#1}

and call

\foo{\begin{tikzpicture}\draw [thin, ->] (-1,0)  -- (0,0);\end{tikzpicture}}

the error is the same.


The problem seems to be specific to babel-spanish. If I try the same code with babel-czech, which makes - into a shorthand, the code works.

  • Does it help to use \shorthandoff ? – percusse Jun 15 '16 at 14:39
  • @percusse I guess it helps, but placed before \ifthenelse – egreg Jun 15 '16 at 14:40
  • @percusse I think the problem is specific with babel-spanish, because it uses a slightly different mechanism for shorthands than standard babel. – egreg Jun 15 '16 at 14:48
  • 1
    @percusse For instance, czech makes - into a shorthand, but the code works. – egreg Jun 15 '16 at 14:55
  • 1
    @TomHirschowitz Sorry, no; for > in Spanish one can disable the “quoting” feature. With French one cannot disable ! and the other special punctuations. It shouldn't happen with XeLaTeX and LuaLaTeX. – egreg Apr 5 '18 at 16:25

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.