I need to patch the following macro from gloss-greek.ldf
(polyglossia
):
\def\greek@numbers{%
\let\latin@alph\@alph%
\let\latin@Alph\@Alph%
\if@greek@numerals
\def\greek@alph##1{\protect\greeknumber{##1}}%
\def\greek@Alph##1{\protect\Greeknumber{##1}}%
\let\@alph\greek@alph%
\let\@Alph\greek@Alph%
\fi}
to the following
\def\greek@numbers{%
\let\latin@alph\@alph%
\let\latin@Alph\@Alph%
\if@greek@numerals
\def\greek@alph##1{\protect\greeknumber{\the##1}}%
\def\greek@Alph##1{\protect\Greeknumber{\the##1}}%
\let\@alph\greek@alph%
\let\@Alph\greek@Alph%
\fi}
(to add the two \the
s).
However I get problems related to different catcodes of #.
I've tried approaches like the ones mentioned in Patching arguments inside a macro but I have failed so far.
Working example:
\documentclass{memoir}
\usepackage{amsmath}
\usepackage{fontspec}
\usepackage{xpatch}
\usepackage{polyglossia}
\setdefaultlanguage{greek}
\setotherlanguage{english}
\newfontfamily\greekfont{Times New Roman}
\usepackage{xpatch}
\tracingpatches
\makeatletter
\newcommand{\patchme}{%
\xpatchcmd{\greek@numbers}{\greeknumber{##1}}{\greeknumber{\the##1}}{}{}
\xpatchcmd{\greek@numbers}{\Greeknumber{##1}}{\Greeknumber{\the##1}}{}{}
}
\makeatother
\begin{document}
\patchme
\begin{subequations}
\begin{align}
a &= b \label{eq:eq1}\\
c &= d \label{eq:eq2}
\end{align}
\end{subequations}
This is \eqref{eq:eq2}? Is it really?
\end{document}
If the patch were applied the reference would appear correct. Also the log reads:
[debug] tracing \patchcmd on input line 28
[debug] analyzing '\greek@numbers'
[debug] ++ control sequence is defined
[debug] ++ control sequence is a macro
[debug] -- nested patching command and parameters in patch
[debug] -> the patching command seems to be nested in the
[debug] argument to some other command
[debug] -> the patch text seems to contain # characters
[debug] -> either avoid nesting or use # characters with
[debug] category code 12 in the patch text
[debug] -> simply doubling the # characters will not work
\makeatletter \xpatchcmd{\greek@numbers}{\greeknumber{##1}}{\greeknumber{\the##1}}{}{} \xpatchcmd{\greek@numbers}{\Greeknumber{##1}}{\Greeknumber{\the##1}}{}{} \makeatother
(note I did not try it)) – Steven B. Segletes Apr 14 '16 at 10:53\xpatchcmd
, and respecifying\def\greek@numbers
as desired in the preamble. Is that solution not acceptable? I suppose your question may be aboutxpatch
itself, rather than about the MWE, which can be fixed through other means. – Steven B. Segletes Apr 14 '16 at 11:44