1

I figured out a minimal working example. If \item good has the same starting word in the search list, the document doesn't compile.

If I write something like \item foo, the document compiles.

\documentclass{article}
\usepackage{xesearch}

\begin{document}
\SearchList{l}{Better}{good job}

\begin{itemize}
\item good
\end{itemize}

happy good job

\end{document}

The error message is

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H   for immediate help.
 ...

l.17 \end{itemize}

Is there any way to fix the issue? My real file has a lot of itemize environments and I hope to run xesearch on arbitary text outside of the itemize environments.

I'm also happy to know how to debug this error, like what the text looks like after the search and replacement.

3
  • 2
    you can try \AddToHook{env/itemize/begin}{\XeTeXinterchartokenstate0 }. But on the whole that looks rather fragile and experimental. Commented Nov 10, 2022 at 11:10
  • 1
    @UlrikeFischer Your solution works on my production file. Would you explain a bit? Your comment then would be an answer. I've no idea how the problem is caused.
    – Gqqnbig
    Commented Nov 10, 2022 at 11:49
  • the search is based on interchar tokens and I disable that. The problem is that the search looks ahead when looking for the second word job and expand commands partly. That can break in various places. You can also try to stop the search with good\vphantom{}. Commented Nov 10, 2022 at 13:26

1 Answer 1

1

The xesearch package provides the commands \StopSearching and \StartSearching, which you can hook to the itemize environment. However, there seems to be a bug with these commands as well, as this leads to an error that the internal macro \xs@String is not defined. Defining this somewhere in the code allows for successful compilation:

\documentclass{article}
\usepackage{xesearch}
\makeatletter
\def\xs@String{}
\makeatother
\AddToHook{env/itemize/begin}{\StopSearching}
\AddToHook{env/itemize/end}{\StartSearching}
\begin{document}
\SearchList{l}{Better}{good job}
\begin{itemize}
\item good
\end{itemize}
happy good job

\end{document}

Result:

enter image description here

Note that the end hook is actually not necessary, the begin hook restricts the scope of \StopSearching to the environment. However, for symmetry I have left it in.

2
  • That's amazing. How do you know \xs@String needs to be fixed? I tried \StopSearching in vain without the \xs@String patch.
    – Gqqnbig
    Commented Nov 10, 2022 at 13:43
  • 1
    If you use \StopSearching without the definition then you get the error ! Undefined control sequence. <XeTeXinterchartoks> \xdef \xs@String {\xs@String. The last command on the first line in such an error message is the command that is undefined, so here that is \xs@String.
    – Marijn
    Commented Nov 10, 2022 at 14:23

You must log in to answer this question.

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