# Best way to use multi-lingual quotes using csquotes package in AUCTeX Emacs

When I write in Arabic (Rt-to-Lt) language I get the quotation marks reversed (the right instaed of left and vice versa) if I want to keep font-locking of AUCTeX setup.

Emacs editor using AUCTeX
Font-locking is right in the first line, but not in the second. However the second line will get the quotations right in the PDF for Arabic.

Output
So you can see the second line has it right in Arabic.

My trial code to fix that

\documentclass[twoside=semi]{scrbook}

\usepackage{polyglossia}
\newfontfamily\arabicfont[Script=Arabic,Ligatures=TeX]{Simplified Arabic}

\usepackage[style=arabic]{csquotes}
\DeclareQuoteStyle[quotes]{arabic}
{\textquotedblright}{\textquotedblleft}
{\textquoteright}{\textquoteleft}

\DeclareQuoteStyle[guillemets]{arabic}
{\guillemotright}{\guillemotleft}
{\guilsinglright}{\guilsinglleft}

\DeclareQuoteOption{arabic}
\DeclareQuoteAlias[quotes]{arabic}{arabic}

\begin{document}

هنا نص باللغة العربية داخل علامتي الاقتباس''.

هنا نص باللغة العربية "داخل علامتي الاقتباس.

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:


ERROR

ERROR: Package csquotes Error: Quote style not defined.


I want to keep font-locking (fontification for quotations) setup unchanged, but change the quotations from within csquotes package. I looked up in the documentation and I didn't find a support for Arabic language for example, but one can add a style and a variant for this language. I tried to reverse the quotation marks in a new style called arabic with two variants quotes and guillemets, but it didn't work. What am I missing?

Notes:

• csquotes Version 5.1d
• Compilation by xetex
• – ClintEastwood Feb 3 '15 at 7:08
• also related: tex.stackexchange.com/q/166337/26295. But it didn't work for me. – doctorate Feb 3 '15 at 9:27
• it is because of the messy appearance of code when writing in Rt-to-Lt and the commands in Lt-to-Rt, a general problem that makes reading the text code an awful experience, especially when you have a lot of quotes (like in a conversation or something like that). – doctorate Feb 3 '15 at 12:32

I don't know arabic, so I don't even know what the correct quotes are in this case.

But what I can tell you is that the command \DeclareQuoteOption can be used only in a configuration file csquotes.cfg. This file can contain new options which can then be used at loading time by the csquotes package. In fact it is loaded by csquotes before processing its options.

So you have to create a file with that name in your document directory with the following contents

\ProvidesFile{csquotes.cfg}

\DeclareQuoteStyle[quotes]{arabic}
{\textquotedblright}{\textquotedblleft}
{\textquoteright}{\textquoteleft}

\DeclareQuoteStyle[guillemets]{arabic}
{\guillemotright}{\guillemotleft}
{\guilsinglright}{\guilsinglleft}

\DeclareQuoteAlias[quotes]{arabic}{arabic}
\DeclareQuoteOption{arabic}

\endinput


At this point your MWE can be reduced to:

\documentclass[twoside=semi]{scrbook}

\usepackage{polyglossia}
\newfontfamily\arabicfont[Script=Arabic,Ligatures=TeX]{Simplified Arabic}

\usepackage[style=arabic]{csquotes}

\begin{document}

هنا نص باللغة العربية داخل علامتي الاقتباس''.

هنا نص باللغة العربية "داخل علامتي الاقتباس.

هنا نص باللغة العربية \enquote{داخل علامتي الاقتباس}.

\end{document}


and this is its output:

The output of \enquote seems to be the one you are expecting.

If you want, you can add

\MakeOuterQuote{"}


in your document and use "..." for your quotes.

MWE:

\documentclass[twoside=semi]{scrbook}

\usepackage{polyglossia}
\newfontfamily\arabicfont[Script=Arabic,Ligatures=TeX]{Simplified Arabic}

\usepackage[style=arabic]{csquotes}
\MakeOuterQuote{"}

\begin{document}

هنا نص باللغة العربية داخل علامتي الاقتباس''.

هنا نص باللغة العربية \enquote{داخل علامتي الاقتباس}.

هنا نص باللغة العربية "داخل علامتي الاقتباس".

\end{document}


The output is the same as above.

• a more generic approach is to add the custom style definitions in the csquotes.cfg file -- as indicated in the same file. \enquote{arabic text} is not an option because of the messy appearance when written inside Rt-to-Lt text. I added the definitions to the csquotes.cfg file and compiled without errors but the problem is that csquotes does not respect the Rt and Lt order of quotes/guillemets; I cannot reverse them no matter where Lt or Rt is placed. – doctorate Feb 3 '15 at 11:39
• @doctorate So why are you using csquotes? Simply invert the quotes in your text. – karlkoeller Feb 3 '15 at 11:42
• good question: to keep the font-locking of the text editor as I said earlier in this post. Better to ask: when csquotes was meant to reverse quotes (see unofficial variant of the newspeak style in the documentation) why is it that when I use arabic it cannot be reversed? Of course, another reason is to toggle seamlessly between variants of style just in case. – doctorate Feb 3 '15 at 11:48
• @doctorate Why don't you define \MakeOuterQuote{"} and use "..." for your quotes? – karlkoeller Feb 3 '15 at 11:52
• I didn't get your idea, but in Arabic I open with  and close with ''. – doctorate Feb 3 '15 at 12:05

Using of quotes in multi-lingual documents is very complicated, given the different possibilities of showing quotes (", '', or << - french), in addition to what language you want to use (Lt-to-Rt) or (Rt-to-Lt) which will inherit values of babel or polyglossia. On the other hand, the csquotes package offers a seamless way to switch between different variants of one style, but I think it has some limitations which I would highlight here that might be of interest for developers in future. On top of that keeping the font-lock of the editor (Emacs + AUCTeX) to enhance readability of the script makes it even a harder task. So there are 2 main players (csquotes and editor's font-lock) interacting to give you the desired effect and I will show my best compromise to satisfy both. I am open to all kinds of suggestions.

Consider this MWE using Ar-En

\documentclass[twoside=semi]{scrbook}
\usepackage{polyglossia}
\setotherlanguages{english}
\newfontfamily\englishfont{Linux Libertine}
\newfontfamily\arabicfont[Script=Arabic,Ligatures=TeX]{Simplified Arabic}
\usepackage[arabic=guillemets,english=guillemets]{csquotes}
\MakeAutoQuote{«}{»}
\begin{document}

هذا نص باللغة العربية «خارج «داخل» الاقتباس».

هذا نص باللغة العربية \enquote{خارج \enquote{داخل} الاقتباس}.

\begin{english}
This is English text «outer «inner» quotations».

This is English text \enquote{outer \enquote{inner} quotations}.
\end{english}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:


Notes:

• Arabic is Rt-to-Lt like Hebrew and Persian, whearas English is Lt-to-Rt
• As you can see \enquote{} is a bad idea if you write with Rt-to-Lt, period.
• csquotes package does not ship with arabic style, this must be defined in csquotes.cfg file (see below)
• \MakeAutoQuote{«}{»} has many advantages (see: https://tex.stackexchange.com/a/39292/26295)
• It is better than \MakeOuterQuote{"} which will give you headache with font-lock alone with this unmatched single " over there see https://emacs.stackexchange.com/q/7942/2443
• To type « and » press C-x 8 < and C-x 8 >, respectively.

Font-lock Code in .init

(font-lock-add-keywords 'latex-mode (list (list "\$$«\\(.+?\\|\n\$$\\)\$$+?\$$\$$»\$$" '(1 'font-latex-string-face t) '(2 'font-latex-string-face t) '(3 'font-latex-string-face t))))


Definitions Code in csquotes.cfg

On my Windows machine this file is in this path:
c:/texlive/2014/texmf-dist/tex/latex/csquotes/csquotes.cfg

\ProvidesFile{csquotes.cfg} % already in the file

% Put your definitions here.

\DeclareQuoteStyle[quotes]{arabic}
{\textquotedblright}{\textquotedblleft}
{\textquoteright}{\textquoteleft}

\DeclareQuoteStyle[guillemets]{arabic}
{\guillemotleft}{\guillemotright}
{\guilsinglleft}{\guilsinglright}

\DeclareQuoteStyle[guillemets]{english}
{\guillemotright}{\guillemotleft}
{\guilsinglright}{\guilsinglleft}

\DeclareQuoteAlias[quotes]{arabic}{arabic}
\DeclareQuoteOption{arabic}

\endinput % already in the file check by yourself


Output with guillemets

Note: see the guillemets variant of english style was added and inverted to match the main language (arabic) of the document. However, this didn't work for quotes! Any idea why? The main reason why I opted for guillemets variants for both Ar and En.

To try quotes change one line in MWE:

\usepackage[arabic=quotes]{csquotes}


Output with quotes

Note: the quotations in Arabic are quite well but they are inverted for English. If I invert defintions in the .cfg file for arabic style I will get right quotations for English but inverted for Arabic. That is the main different with guillemets, the latter tends to be more consistent with both languages, I am rather interested if someone knows why such a puzzling behavior in csquotes package --- obviously a limitation.

Conclusion
Using guillemets instead of quotes proves to be a good strategy to have consistent quotation behavior for the two languages and they don't mess with the Rt-to-Lt text as when \enquote is used, plus they can be font-locked in AUCTeX with no fuss (see below).