olsak / OpTeX

OpTeX - LuaTeX format with extended Plain TeX macros
http://petr.olsak.net/optex/
35 stars 14 forks source link

Disable \sb replacement in verbatim #42

Closed cao- closed 3 years ago

cao- commented 3 years ago

With \mathsbon in verbatim mode something like \int_a^b gets replaced by \int _a^b, even if it shouldn't in my opinion.

Of course I can do something like

\mathsboff
\begtt
\int_a^b
\endtt
\mathsbon

to get the desired result. But this should be the default behaviour, without having to specify it.

I tried to redefine \begtt \endtt in the following way:

\_def\_savemathsb{\_ifmathsb\_mathsboff\_def\_restoremathsb{\_mathsbon}\_else
                             \_def\_restoremathsb{}\_fi}

\_def\begtt{\_savemathsb \_par \_begingroup \_adef\%##1\_relax{\_relax}\_begtti}

\_ea\_def\_ea\_startverb \_ea#\_ea1\_csstring\\endtt#2^^J{%
   \_prepareverbdata\_tmpb{#1^^J}%
   \_ea\_printverb \_tmpb\_end
   \_par
   \_endgroup \_ttskip
   \_isnextchar\_par{}{\_noindent}%
   \_restoremathsb
}

Now I can simply type

\begtt
\int_a^b
\endtt

without having to switch off the Lua \sb replacement.

But I guess that something automatic like this can't be done for inline verbatim or for \verbinput or for \code, because the \mathsboff takes effect only from the following input line. Am I right?

olsak commented 3 years ago

This is very good idea! I implemented it in my last commit. Thank you. It works in \verbinput too.

cao- commented 3 years ago

Thank you for having implemented my idea.