# \usetikzlibrary should be used only in preamble in case of french babel

The compilation of the following MWE (Edit: The babel library is now loaded in the preamble, as needed (thanks to an @egreg's comment), and another one, no matter which one, is loaded after the preamble.):

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage[french]{babel}
\usetikzlibrary{babel}
\begin{document}
\usetikzlibrary{shapes.misc}
\end{document}


fails with the error:

Runaway argument?
! Paragraph ended before \pgf@parseid was complete.
\par


(whatever the tikz library used in the document body).

But if either:

• babel package with french option is not used, or
• \usetikzlibrary in the document body is moved in the preamble,

everything works like a charm (the \usetikzlibrary{babel} has nothing to do with the problem, it is just recommended when babel package is loaded, especially with the french option).

What's the reason of this error and how to circumvent it?

• \usetikzlibrary should be used in the preamble no matter what. – egreg Feb 22 '15 at 21:09
• I think @egreg means that it should only be used in the preamble. At least, I hope so. [If I don't have any pictures in a document, I don't even load tikz!] – cfr Feb 22 '15 at 21:13
• @egreg Why? That's not mentioned in the tikz documentation. The reason of my question is that I have to gather, in a single (main) source file, source (sub)files from several authors, some of them containing \usetikzlibrary and I'd prefer to let these commands in the subfiles. – Denis Bitouzé Feb 22 '15 at 21:14
• @DenisBitouzé The project is yours. But surely the babel library must be in the preamble: after \begin{document} it's too late for its fixes to work. – egreg Feb 22 '15 at 21:15
• @egreg The babel library is just an example. In my real project, this library is indeed in the preamble and that's other libraries (e.g. the shapes.misc one) that I'd like to load after the preamble. – Denis Bitouzé Feb 22 '15 at 21:22

If you need to load code after babel has made characters active it is usually best to locally undo that, here it seems to work to turn off :

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage[french]{babel}
\usetikzlibrary{babel}
\begin{document}
\shorthandoff{:}%
\usetikzlibrary{shapes.misc}
\shorthandon{:}%
\end{document}

• Wouldn't this be expected to be done by \usetikzlibrary{babel}? I mean, with this library, Till Tantau already helped a lot package babel users (especially French ones) but maybe the situation I described could be taken in account. Another strange thing is the /cvsroot/... absolute path. – Denis Bitouzé Feb 23 '15 at 13:11
• @DenisBitouzé I know nothing about tikz and little about babel, so I have very few expectations here sorry. I just answered as I made a guess and it seemed to work. You could always raise it with the tikz maintainers that (even without explicitly flagging babel) it could protect itself against active : – David Carlisle Feb 23 '15 at 13:29
• Done here. – Denis Bitouzé Feb 23 '15 at 16:46