2

I get some macros to enable me to generate a document in three different languages from the same .txt file (for example a CV). But the format of the quote is dependent of the order in which I load the languages with babel instead of the selected languages. For example in the MWE the selected language is English, but the quotation format is French since this is the last loaded language in babel.

\documentclass[]{article}
\usepackage[UKenglish,german,french]{babel}
\usepackage[autostyle=true]{csquotes}
% define the commands to switch and the flags in LaTeX
\newcommand{\GERMAN}{\germantrue \frenchfalse \englishfalse
                     \selectlanguage{german}}
\newcommand{\FRENCH}{\germanfalse  \frenchtrue \englishfalse
                     \selectlanguage{french}}
\newcommand{\ENGLISH}{\germanfalse  \frenchfalse \englishtrue
                      \selectlanguage{UKenglish}}
\newif\ifgerman \germantrue
\newif\iffrench \frenchtrue
\newif\ifenglish \englishtrue

% then choose one language to be displayed
%\GERMAN
%\FRENCH
\ENGLISH
    \newcommand\hide[1] {}
    \newcommand\german[1] {\ifgerman #1 \else \fi}
    \newcommand\french[1] {\iffrench #1 \else \fi}
    \newcommand\english[1] {\ifenglish #1 \else \fi}
    \begin{document}
    \german{\enquote{Etwas}}\french{\enquote{Quelque chose}}\english{\enquote{something}}
\end{document}

So the result is ≪ something ≫ intead of `something'

How should I change the code to make that the autostyle consider the selected language ?

4
  • 1
    What about \newcommand{\english}[1]{\ifengish\selectlanguage{UKenglish}#1\fi}?
    – jon
    Commented Apr 4, 2016 at 18:59
  • Thanks you @jon. It seems to work. Can you explain what make the difference ?
    – Pierrick
    Commented Apr 4, 2016 at 19:25
  • 1
    Don't load packages inside \newcmmands. As to the why, I'd have to dig deeper into the question.
    – jon
    Commented Apr 4, 2016 at 19:32
  • I also found that putting babel inside of the newcommand like this work: \newcommand{\GERMAN}{\germantrue \frenchfalse \englishfalse \usepackage[german]{babel}\selectlanguage{german}} And removing the line : \usepackage[UKenglish,german,french]{babel} But I don't like this solution.
    – Pierrick
    Commented Apr 4, 2016 at 19:37

1 Answer 1

3

You are calling your command to early: babel sets the main language at begin document and so overwrites your \selectlanguage. If you move your commands behind \begin{document} or use \AtBeginDocument it works fine:

\documentclass[]{article}
\usepackage[UKenglish,german,french]{babel}
\usepackage[autostyle]{csquotes}

% define the commands to switch and the flags in LaTeX
\newcommand{\GERMAN}{\germantrue \frenchfalse \englishfalse
                     \selectlanguage{german}}
\newcommand{\FRENCH}{\germanfalse  \frenchtrue \englishfalse
                     \selectlanguage{french}}
\newcommand{\ENGLISH}{\germanfalse  \frenchfalse \englishtrue
                      \selectlanguage{UKenglish}}
\newif\ifgerman \germantrue
\newif\iffrench \frenchtrue
\newif\ifenglish \englishtrue

% then choose one language to be displayed
\AtBeginDocument{\GERMAN}
%\FRENCH
%%\ENGLISH
    \newcommand\hide[1] {}
    \newcommand\german[1] {\ifgerman #1 \else \fi}
    \newcommand\french[1] {\iffrench #1 \else \fi}
    \newcommand\english[1] {\ifenglish #1 \else \fi}
\begin{document}\languagename
    \german{\enquote{Etwas}}\french{\enquote{Quelque chose}}\english{\enquote{something}}
\end{document}

You must log in to answer this question.

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