2

I have to use the tikzlibrary babel to avoid conflicts with the french babel package. Nevertheless, I face a problem each time I try to draw a plot inside a margin note (Important: My plot is created with pgfplots and I use the marginnote package).

\documentclass[dvipsnames,11pt]{article}

\usepackage{amsfonts}
\usepackage[a4paper,vmargin=2cm,left=1cm,textwidth=15cm,marginparwidth=4cm]{geometry}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{lipsum}
\usepackage{marginnote}
\usepackage[french]{babel}

\pgfplotsset{compat=1.16}
\usetikzlibrary{babel}


\begin{document}

    % The code below works (It doesn't use pgfplots).
    \lipsum[3]
    \marginnote{\begin{tikzpicture}\draw (0,0) -- (1,1); \end{tikzpicture}}
    \lipsum[4]

    % The code below doesn't work (conflict with \usetikzlibrary{babel})
    \lipsum[3]
    \marginnote{
        \begin{tikzpicture}
            \begin{axis}[width=3cm, axis lines=none]
            \addplot [
                domain=0:1, 
                samples=10, 
            ]
            {x};
            \end{axis}
        \end{tikzpicture}
        }
    \lipsum[4]

\end{document}

The error I get is:

Argument of \pgfplots@addplotimpl@expression@curly has an extra }. \lipsum

So I wonder if there is a safely way to use the tikzlibrary babel in this scenario.

If I don't use a margin note, I could remove the problematic library import line \usetikzlibrary{babel} using the workaround \shorthandoff as described in this post. See also the code below:

\documentclass[dvipsnames,11pt]{article}

\usepackage{amsfonts}
\usepackage[a4paper,vmargin=2cm,left=1cm,textwidth=15cm,marginparwidth=4cm]{geometry}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{lipsum}
\usepackage{marginnote}
\usepackage[french]{babel}

\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
%\usetikzlibrary{babel}


\begin{document}

    % The code below doesn't work without \usetikzlibrary{babel} or \shorthandoff{:}
    \begin{tikzpicture}
    \shorthandoff{:}  % line added
    \begin{axis}[
        axis lines = none,
    ]
    \addplot [name path=A,domain=-5:1,samples=100] {1/pi*1/(x^2+1)};
    \addplot [name path=B,domain=-5:1] {0};
    \addplot [color=blue!30!white] fill between [
    of=A and B, soft clip = {domain = -5:1}  % clash with the babel french package because of this line.
    ];
    \addplot [
        domain=-5:5, 
        samples=100, 
        color=black,
    ]
    {1/pi*1/(x^2+1)};
    \end{axis}
    \end{tikzpicture}
\end{document}

But if I wrap the same code inside a marginnote command, I get fatal errors in all cases:

\documentclass[dvipsnames,11pt]{article}

\usepackage{amsfonts}
\usepackage[a4paper,vmargin=2cm,left=1cm,textwidth=15cm,marginparwidth=4cm]{geometry}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{lipsum}
\usepackage{marginnote}
\usepackage[french]{babel}

\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
%\usetikzlibrary{babel}


\begin{document}
% I don't know how to make this code work with or without using \usetikzlibrary{babel}...
    \marginnote{
    \begin{tikzpicture}
    %\shorthandoff{:} If I uncomment this line, I get the error: Argument of \pgfkeys@code has an extra }. \end
    \begin{axis}[
        axis lines = none,
    ]
    \addplot [name path=A,domain=-5:1,samples=100] {1/pi*1/(x^2+1)};
    \addplot [name path=B,domain=-5:1] {0};
    \addplot [color=blue!30!white] fill between [
    of=A and B, soft clip = {domain = -5:1}  
    ];
    \addplot [
        domain=-5:5, 
        samples=100, 
        color=black,
    ]
    {1/pi*1/(x^2+1)};
    \end{axis}
    \end{tikzpicture}}
\end{document}

How to solve the above problem?

3
  • Welcome to TeX.SE! Rather than tell us you get "fatal errors", tell us what the errors are and what exactly is going wrong. Nov 22, 2019 at 11:32
  • You could just put the tikzpicture in a \savebox, which you can use in \marginnote{...}.
    – user194703
    Nov 22, 2019 at 16:35
  • @Schrödinger's cat I've used a \savebox but the problems are the same as decribed above. But I've found a solution to my problem that I describe below. Nov 23, 2019 at 9:42

1 Answer 1

2

I've wrapped the marginnote with curly braces and I've used the command \shorthandoff{;:!?} (\shorthandoff{:} is enough in my case) just before the margin note: It solves the problem.

@Schrödinger's cat

@dgoodmaniii

Thanks for your answers

\documentclass[dvipsnames,11pt]{article}

\usepackage{amsfonts}
\usepackage[a4paper,vmargin=2cm,left=1cm,textwidth=15cm,marginparwidth=4cm]{geometry}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{lipsum}
\usepackage{marginnote}
\usepackage[french]{babel}

\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{babel}


\begin{document}

    \lipsum[3]
    {\shorthandoff{;:!?}% or \shorthandoff{:} in this case  
    \marginnote{%
    \begin{tikzpicture}
                \begin{axis}[
                    axis lines = none,
                ]
                \addplot [name path=A,domain=-5:1,samples=100] {1/pi*1/(x^2+1)};
                \addplot [name path=B,domain=-5:1] {0};
                \addplot [color=blue!30!white] fill between [
                of=A and B, soft clip = {domain = -5:1}
                ];
                \addplot [
                    domain=-5:5, 
                    samples=100, 
                    color=black,
                ]
                {1/pi*1/(x^2+1)};
                \end{axis}
    \end{tikzpicture}
    }}
    \lipsum[4]

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .