Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to have my pgfplot legend automatically translated wrt the language used in my article. Thus, I use to use the translator package, which a very easy and pleasant solution. It works like a charm until I externalize the legend into a reference.

In the follow MWE, one can observe that the translate command works in nameref, in legend entries but not with legend to name.

    \documentclass{article}
    \usepackage[english,french]{babel}
    \usepackage{translator}
    \languagepath{French}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage{tikz,pgfplots}
    \usepackage{nameref}

    \begin{document}
    \providetranslation[to=French]{My section}{Ma section}%
    \section{\translate{My section}\label{marker}}
    In section \nameref{marker} we defined...

    \begin{figure}[!h]
    \centering
    \begin{tikzpicture}
    \providetranslation[to=French]{Zero line}{Ligne zéro}%
    \providetranslation[to=French]{Quadratic line}{Ligne quadratique}%
    \begin{axis}[ymin=0, ymax=80,legend entries={\translate{Zero line},\translate{Quadratic line}}]
    \addplot {x*0}; 
    \addplot {x^2+50};
    \end{axis}
    \end{tikzpicture}
    \caption{Figure with internal legend}
    \end{figure}
    \begin{figure}[!h]
    \centering
    \begin{tikzpicture}
    \providetranslation[to=French]{Zero line}{Ligne zéro}%
    \providetranslation[to=French]{Quadratic line}{Ligne quadratique}%
    \begin{axis}[ymin=0, ymax=80,legend entries={\translate{Zero line},\translate{Quadratic line}},legend to name=legend]
    \addplot {x*0}; 
    \addplot {x^2+50};
    \end{axis}
    \end{tikzpicture}
    \caption{Figure with external legend}
    \ref{legend}\newline
    \end{figure}
    \end{document}

producing:

Example output

Is there a way to solve that issue ?

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

The external legend gets put into its own tikzpicture environment, so your translations aren't available when the legend gets put together. If you provide the translations outside the tikzpicture, everything works fine:

\documentclass{article}
\usepackage[english,french]{babel}
\usepackage{translator}
\languagepath{French}    

\usepackage[utf8]{inputenc}
\usepackage{tikz,pgfplots}
\usepackage{nameref}


\providetranslation[to=French]{Zero line}{Ligne zéro}%
\providetranslation[to=French]{Quadratic line}{Ligne quadratique}%

\begin{document}
\providetranslation[to=French]{My section}{Ma section}%
\section{\translate{My section}\label{marker}}
In section \nameref{marker} we defined...

\begin{figure}[!h]
\centering

\begin{tikzpicture}
\begin{axis}[ymin=0, ymax=80,legend entries={\translate{Zero line},\translate{Quadratic line}},legend to name=legend]
\addplot {x*0}; 
\addplot {x^2+50};
\end{axis}
\end{tikzpicture}
\caption{Figure with external legend}
\ref{legend}\newline
\end{figure}
\end{document}
share|improve this answer
1  
You right... More specifically, the translation need to be declare in the same environment than the one where \ref is used or upper (like you do, in the preamble for example). Thanks –  Sigmun Apr 17 '12 at 14:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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