I have used the package xesearch https://www.ctan.org/pkg/xesearch?lang=en xesearch in my header to automatically replace shorthand notations:

\SearchList{list1}{Very Long Search Replacement 1}{SRa}
\SearchList{list2}{Very Long Search Replacement 2}{SRb}

Which when put into the header acts to search and replace:

"SRa and SRb" into

"Very Long Search Replacement 1 and Very Long Search Replacement 2"

in the resulting document.

Which is great!

But it did occur to me that if I could have xesearch replace the placeholders with LaTeX commmands, and run them, at compile time that would be useful, eg:

\SearchList{list1}{\SomeGreatLaTeXCommand[with options]}{SRa}

So that putting SRa in your code would result in \SomeGreatLaTeXCommmand[with options] being compiled and same with SRb compiling as \AReallyFantasticLaTeXCommand

I am aware that one can make substitute LaTeX commands as follows:


Does anybody know a way for the xesearch package to be used in this manner? If xesearch cannot be put to work this way, is there another package that could do this type of automatic search and replace? Is there a way to do this without XeLaTeX? Or, is this a really very stupid question, because LaTeX/TEX is a programming language?

  • xesearch is very cool, but wouldn't sed or awk be more appropriate for string manipulation? (Off-topic: I would avoid using \bc in that way. In the end it just obfuscates the code.)
    – jon
    Commented Dec 7, 2015 at 6:35
  • I wouldn't know how to use sed or awk, at least not at this point :)
    – A Feldman
    Commented Dec 8, 2015 at 6:32

1 Answer 1


Yes, one can use commands in the replacement texts. Actually almost all examples in the xesearch documentation use commands. I have not tried to see if commands can be used which examine what comes next, but things like \begin{center} work.

Update adds an example showing that not everything is possible (at least out of the box):

% compile with xelatex




Hello World!


test of xesearch

% compile with xelatex
\documentclass[varwidth, preview, border=10pt]{standalone}

  This is some nl nonsensical text.

  We may even try nl[30pt] crazy things but it does not\\[30pt] work.

enter image description here

  • Thanks so much. I guess I had "assumed" that it did not do that without some kind of extra wizardry.
    – A Feldman
    Commented Dec 16, 2015 at 15:28
  • @AFeldman I understand, because it does look magical ...
    – user4686
    Commented Dec 16, 2015 at 16:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .