Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighting math in LaTeX-style math-mode delimiters \(…\) #6

Open
ghost opened this issue Apr 9, 2023 · 5 comments
Open

Highlighting math in LaTeX-style math-mode delimiters \(…\) #6

ghost opened this issue Apr 9, 2023 · 5 comments

Comments

@ghost
Copy link

ghost commented Apr 9, 2023

Please integrate http://tex.stackexchange.com/a/443317 or http://tex.stackexchange.com/a/426036 (or an equivalent way of solving the issue) into soul.sty.

Test case failing as of now:

\documentclass{standalone}
\usepackage[x11names]{xcolor}
\usepackage{soul}
\begin{document}
Please, highlight \hl{\(e^{i\pi}=-1\) and \emph{The Pythagorean Theorem \(a^2+b^2=c^2\)}}.
\end{document}
@ghost ghost changed the title Highlighting math in LaTeX-style math-mode delimiters \(\) Highlighting math in LaTeX-style math-mode delimiters \(…\) Apr 9, 2023
@michaelcadilhac
Copy link

Seconded; it's not a limitation that is easy to Google or know about without reading the finer details of the documentation. It's also very unexpected, and there's a solution provided that works immediately.

@u-fischer
Copy link

Well the code with l3regex is too slow imho, but the etl-code from @Skillmon could be ok.

But there are clearly not enough test files in the repository to really check if they are unwanted side effects. So if you want that, help me to improve the test situation: give me three small documents which tests some special soul case.

u-fischer added a commit that referenced this issue Sep 19, 2023
@michaelcadilhac
Copy link

Haha, is that a trade? :-) What's the test format?

@ghost
Copy link
Author

ghost commented Sep 20, 2023

@u-fischer I often use LaTeX math \(…\), emphasis, and German quotation marks in German texts. Therefore, my test case is this:

\documentclass[ngerman]{article}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[x11names]{xcolor}
\usepackage{soul}
\begin{document}
Bitte \hl{die „schönste“ Gleichung \(e^{i\pi}=-1\) und \emph{den „Satz des Pythagoras“ \(a^2+b^2=c^2\)}} farbig hinterlegen.
% \hl{die schönste Gleichung \(e^{i\pi}=-1\)}%%% for the purposes of this very bug report, you might wish not to mix the issues and take, instead of the line above, only this line.
\end{document}

@Skillmon
Copy link

Skillmon commented Sep 20, 2023

@u-fischer the code using \etl_token_replace_all_deep:nNn needs to step through the entire list twice (with all checks for head-is-space and head-is-group), I think the performance could further be improved by coding up some customary replacer with \etl_act:nnnnn that only needs to step through the list once.

I didn't benchmark this, but I reckon this is faster (it also doesn't use \etl_token_if_eq:NNTF, which is overkill because it requires string-comparison plus the \token_if_eq_meaning:NNTF -- something that's probably unnecessary for this application):

\documentclass{article}

\usepackage{soul}
\usepackage{etl}

\ExplSyntaxOn
\cs_set_eq:NN \SOUL_math_start: \(
\cs_set_eq:NN \SOUL_math_end:   \)
\cs_set_eq:Nc \SOUL_start:n { SOUL@start }
\cs_set_protected:cpn { SOUL@start } #1
  { \exp_args:Ne \SOUL_start:n { \__SOUL_math_fixer:n {#1} } }
\cs_new:Npn \__SOUL_math_fixer:n
  {
    \etl_act:nnnnn
      \__SOUL_math_fixer_aux:nN
      { \use_i:nn { ~ } }
      \__SOUL_math_fixer_aux:nn
      {}
  }
\cs_new:Npn \__SOUL_math_fixer_aux:nn #1#2
  { { \__SOUL_math_fixer:n {#2} } }
\cs_new:Npn \__SOUL_math_fixer_aux:nN #1#2
  {
    \token_if_eq_meaning:NNF #2 \SOUL_math_start:
      { \token_if_eq_meaning:NNF #2 \SOUL_math_end: \use_iii:nnn }
    $ \use_none:n { \exp_not:N #2 }
  }
\ExplSyntaxOff

\begin{document}
Bitte \hl{\emph{den Satz des Pythagoras \(a^2+b^2=c^2\)}} farbig hinterlegen.
\end{document}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants