# How to patch a command from leipzig.sty

As shown in Issues with leipzig and glossaries used together, there is a problem when using the package leipzig with the glossaries package since the leipzig package relies on deprecated commands from glossaries.

The answer to the question solves the issue, but the answer suggests modifying the .sty file, which I would rather not do.

I have tried to patch the \SetLeipzigDisplayStyle command, but I have not been successful. According to egreg's answer to Please tutor the usage of patchcmd and xpatch, one should use xpatch when trying to patch a command with an optional argument. \SetLeipzigDisplayStyle is such a command, but trying to patch it with \xpatchcmd does not work for me. How can I fix the issue without resorting to (copying and) modifying the .sty file?

## MWE

% !TEX TS-program = arara
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
% arara: pdflatex

\documentclass{article}

\usepackage{expex}

\usepackage[nomain,nostyles]{glossaries}
\usepackage{glossary-inline}
\usepackage{leipzig}
\makeglossaries

\usepackage{xpatch}
\xpatchcmd{\SetLeipzigDisplayStyle}{%
\defglsdisplay[#1]{\leipzigfont{##1}##4}%
\defglsdisplayfirst[#1]{\firstleipzigfont{##1}##4}%
}{%
\renewcommand*{\glstextformat}[1]{\leipzigfont{#1}}%
}{}{}

\begin{document}

\ex
\begingl
\gla mulle//
\glb \First\Sg:\Dat{}//
\endgl
\xe

go.\Pst{}

\printglossary[style=inline,type=\leipzigtype]

\end{document}


You can see that it still produces the problem noted in Issues with leipzig and glossaries used together.

• @GonzaloMedina I'm not getting that error I don't think? I just tried searching the .log file for that error and nothing comes up. – Adam Liter Mar 2 '15 at 3:27
• @AdamLiter: Your patch merely seems to attempt to redefine \SetLeipzigDisplayStyle. Why not just redefine it then rather than patching it? Also, do you want to redefine it to ..##1.. rather than ..#1..? – Werner Mar 2 '15 at 4:53
• @AdamLiter You're not trying a patch, as the text you want to substitute is the whole replacement text of the macro. So, if this patch were successful, it wouldn't be different from doing \renewcommand. – egreg Mar 2 '15 at 7:39
• @AdamLiter Sorry about that. Most probably some leftover auxiliary file I had on my machine. – Gonzalo Medina Mar 2 '15 at 13:58

I don't think it's possible to do patches with etoolbox when the search text contains ## (note that xpatch is built upon etoolbox).

Also, the requested patch is just equivalent to

\renewcommand*{\SetLeipzigDisplayStyle}[1]{%
\renewcommand*{\glstextformat}[1]{\leipzigfont{#1}}%
}


so it's not clear why you're looking for a patch.

By the way, xpatch is not strictly needed for the particular purpose, as \SetLeipzigDisplayStyle is not defined with an optional argument.

If you insist in doing a patch,

\usepackage{regexpatch}
\xpatchcmd{\SetLeipzigDisplayStyle}
{\defglsdisplay[#1]{\leipzigfont{##1}##4}%
\defglsdisplayfirst[#1]{\firstleipzigfont{##1}##4}}
{\renewcommand*{\glstextformat}[1]{\leipzigfont{#1}}}
{}{}


does the job.


\ifx\test\SetLeipzigDisplayStyle\message{EQUAL}\fi


I find EQUAL in the log file, so patching is indeed not necessary and a redefinition should be used.

Probably

• Whether this will do the job connected with the interaction between leipzig and glossaries is beyond the scope of the question. The proposed patch doesn't seem to solve the problem to begin with. – egreg Mar 2 '15 at 8:39
• Using your test in a .tex file that is using a modified version of leipzig also returns EQUAL in the .log file, but the behavior is different. I'm so confused. – Adam Liter Mar 2 '15 at 16:01
• @AdamLiter I fixed the source; but I don't find differences between the behaviors with \regexpatchcmd and \renewcommand – egreg Mar 2 '15 at 16:31