4

Is there an alternative to \xpatchcmd from the xpatch package which supports placeholders as in this virtual example:

\newcommand{\mycommand}{this is important \foo this is not \bar but this is}
\xpatchcmd{\mycommand}{\foo .* \bar}{}{}{}

The aim is to achieve the same as

\newcommand{\mycommand}{this is important but this is}
4

No, it's not possible with xpatch, but it is with the (experimental) regexpatch package:

\documentclass{article}
\usepackage{regexpatch}

\newcommand{\mycommand}{this is important \foo this is not \bar but this is}

\regexpatchcmd{\mycommand}{\c{foo} .* \c{bar}}{}{}{}

\begin{document}

\mycommand

\texttt{\meaning\mycommand}

\end{document}

Note that control sequences in the search regular expression must be denoted by \c{<cs-name>} as in the example.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.