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}
到以下
\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}
(添加两个\the
s)。
然而我遇到了与# 的不同 catcode 相关的问题。
我尝试过修补宏内的参数但我至今都失败了。
工作示例:
\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}
如果应用了补丁,引用将看起来正确。日志内容如下:
[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
答案1
据我所知,使用##
with etoolbox
(内部使用)修补命令是不可能的。xpatch
我不确定为什么你需要\the
在那个地方,因为有没有它输出都是一样的。无论如何,我更喜欢\number
。
可以使用 进行修补regexpatch
。 可以一次性完成所有修补,注意我们要用 替换每次出现的{##1}
,{\number##1}
因此我们可以使用\xpatchcmd*
。
\documentclass{memoir}
\usepackage{amsmath}
\usepackage{fontspec}
\usepackage{regexpatch}
\usepackage{polyglossia}
\setdefaultlanguage{greek}
\setotherlanguage{english}
\newfontfamily\greekfont{Times New Roman}
\makeatletter
\xpatchcmd*{\greek@numbers}
{{##1}}
{{\number##1}}
{\typeout{Hurray!}}{\typeout{Rats!}}
\makeatother
\begin{document}
\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}
以下是终端输出的相关部分:
(/usr/local/texlive/2015/texmf-dist/tex/latex/polyglossia/gloss-english.ldf)
Hurray!
(./doublehash.aux) (/usr/local/texlive/2015/texmf-dist/tex/latex/tipa/t3cmr.fd)
[1] (./doublehash.aux) )
Output written on doublehash.pdf (1 page).
答案2
如果问题在于如何修复 MWE,那么可以通过避免使用 totally 来修复,而仅仅在序言中xpatch
重新指定 total 所需的定义。\greek@numbers
\documentclass{memoir}
\usepackage{amsmath}
\usepackage{fontspec}
\usepackage{polyglossia}
\setdefaultlanguage{greek}
\setotherlanguage{english}
\newfontfamily\greekfont{Times New Roman}
\makeatletter
\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}
\makeatother
\begin{document}
\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}
然而,如果 OP 问题的真正目的是了解其论点中为什么\xpatchcmd
不喜欢的本质##1
,那么这个答案就没有任何意义。
##1
下面是一个更简单的 MWE,用于在宏中演示 的问题\xpatchcmd
。如果补丁有效,结果将是Q(C)
,而不是B(C)
。
\documentclass{article}
\usepackage{xpatch}
\def\A{\def\B##1{B({##1})}}
\xpatchcmd{\A}{B({##1})}{Q({##1})}{\xdef\result{successful}}{\xdef\result{unsuccessful}}
\A
\begin{document}
\B{C}. Patch was \result.
\end{document}