How can I conditionally designate an active quote in csquotes.cfg?
Upon seeing \MakeAutoQuote
or \MakeAutoQuote*
, csquotes
defines \csq@string@<number>
for both arguments in a suitable way. The <number>
represents the decimal ASCII codes of the UTF-8 representation of the character, separated by periods if multibyte.
However, the package already provides the infrastructure for the conversion.
\begin{filecontents}{csquotes.cfg}
\MakeAutoQuote{‘}{’}
\MakeAutoQuote*{“}{”}
\end{filecontents}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{csquotes}
\makeatletter
\def\ConditionalMakeAutoQuote#1#{%
\def\cfr@star{#1}\CMAQ@
}
\def\CMAQ@#1#2{%
\csq@ifutfchar{#1}
{\csq@ifvalidutf{#1}
{\ifcsundef{csq@string@\csq@number{#1}}
{\expandafter\MakeAutoQuote\cfr@star{#1}{#2}}
{}
}%
{\csq@err@utf}}
{\csq@ifvalidchar{#1}
{\ifcsundef{csq@string@\number`#1}
{\expandafter\MakeAutoQuote\cfr@star{#1}{#2}}
{}}%
{\csq@err@char}}}
\makeatother
\ConditionalMakeAutoQuote{‘}{’}
\ConditionalMakeAutoQuote*{“}{”}
\begin{document}
‘abc’
“abc”
‘abc “abc” abc’
\end{document}
I get the same result, namely
with or without the csquotes.cfg
file, which is read just after csquotes.def
, so before any possible definition of quoting characters in the document.