1

I need to print the et al. output from \textcite{} (biblatex Pkg) in italics. As stated in this answer this can be achieved by using \xpatchbibmacro{} from the xpatch package.

Having this command either in the document itself or in a cls file providing a latex2e class works without problems. Though, when using the command in an ExplClass the patching stops working.

Is there anything one can do to make the patching work in an ExplClass, or should this be reported as bug to the xpatch maintainer(s)?


MWE

Compilable tex file

\documentclass{TestExplClass}

\addbibresource{biblatex-examples.bib}

\begin{document}
  \textcite{companion} \citeauthor{companion}
  \printbibliography
\end{document}

The called cls file

\NeedsTeXFormat{LaTeX2e}
\RequirePackage{ expl3 , xpatch }
\ProvidesExplClass
  {TestExplClass}
  {2017/10/22}
  {0.1}
  {Class that is having problems}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
\ProcessOptions\relax

\LoadClass{report}

\RequirePackage[english]{babel}
\RequirePackage{csquotes}
\RequirePackage[backend=biber,style=chem-angew]{biblatex}

\xpatchbibmacro{name:andothers}{\bibstring{andothers}}{\bibstring[\emph]{andothers}}{}{}

\endinput
lcnittl
  • 343
  • Why are you using Expl class here? Which expl3 content is there? I can see none directly -- it is hidden of course in expl3 and xpatch. I can imagine that you get in trouble with the catcode regime of expl3 here that lets \xpatchbibmacro fail... –  Oct 22 '17 at 15:30
  • The MWE is just an excerpt from a much larger cls file with several hundred lines, just, as needed for an MWE I cut it down to the minimum where it stops working, in this is the (already) use of the Expl class itself. – lcnittl Oct 22 '17 at 15:34
  • A MWE has a compilable example document at least, not just the class. –  Oct 22 '17 at 15:35
  • @ChristianHupfer is such a failure possible without any error or warning in the log? -- Compilable file comes in a minute. – lcnittl Oct 22 '17 at 15:38
  • 2
    I don't know much about \xpatchbibmacro, but I really feel it is connected to \ExplSyntaxOn and \ExplSyntaxOff - regime. If you try \AtBeginDocument{\xpatchbibmacro{...}} it works as well as with by adding \ExplSyntaxOff just before \xpatchbibmacro explicitly (which is not meant this way by the developing team of expl3, however. I think the : in name:andothers confuses expl3 possibly –  Oct 22 '17 at 15:48
  • @ChristianHupfer Amazing, that's already the answer I guess. Thanks a lot! Do you think this should be reported to xparse, or is usage of AtBeginDocument{...} a (let's say) normal thing? Or rather a problem with expl3? – lcnittl Oct 22 '17 at 15:53
  • 1
    \AtBeginDocument is pretty widely used. At lot of LaTeX code relies on the those \@begindocumenthook contents added with \AtBeginDocument, e.g. hyperref doing a lot of redefinitions of \section, \label etc. with \AtBeginDocument –  Oct 22 '17 at 15:54

1 Answers1

4

The easiest way to prevent such problems with expl3 is to jump out of the \ExplSyntaxOn...\ExplSyntaxOff regime, by shifting the \xpatchbibmacro statement into \AtBeginDocument, keeping the : in name:another 'alive' in the sense of traditional TeX/LaTeX

The patching should occur on document level anyway, so \AtBeginDocument is the right place to do so, in my point of view.

\NeedsTeXFormat{LaTeX2e}
\RequirePackage{ expl3 , xpatch }
\ProvidesExplClass
  {TestExplClass}
  {2017/10/22}
  {0.1}
  {Class that is having problems}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
\ProcessOptions\relax

\LoadClass{report}

\RequirePackage[english]{babel}
\RequirePackage{csquotes}
\RequirePackage[backend=biber,style=chem-angew]{biblatex}

\AtBeginDocument{
  \xpatchbibmacro{name:andothers}{\bibstring{andothers}}{\bibstring[\emph]{andothers}}{\typeout{Success}}{\typeout{Failure}}
}
\endinput

MWE - code (unchanged from O.P.)

\documentclass{TestExplClass}

\addbibresource{biblatex-examples.bib}

\begin{document}
  \textcite{companion} \citeauthor{companion}
  \printbibliography
\end{document}

enter image description here