TexSoup icon indicating copy to clipboard operation
TexSoup copied to clipboard

Control spaces "\ " in math mode don't make the roundtrip

Open ivanistheone opened this issue 5 years ago • 2 comments
trafficstars

People often use \ (called control space) to insert a little extra space in math mode—to avoid the default behaviour of ignoring math spaces.

In TexSoup these get eaten up somehow, so when serialize back out, the tex is different:

Failing test case:

def test_contol_space_command():
    """A control space "\ " can be used to insert extra spacing in math mode."""
    math_with_spaces = r"""$a \ = \ \sin\theta$"""
    soup = TexSoup(math_with_spaces)
    assert str(soup) == math_with_spaces, 'Control spaces not preserved in math'
Screen Shot 2020-10-18 at 1 10 39 AM

expected: $a \ = \ \sin\theta$

observed: $a \=\\sin\theta$

Here are the tokens in case that's helpful:

  '$'_MathSwitch
  'a '_Text
  '\'_Escape
  ' = '_Text
  '\'_Escape
  ' '_MergedSpacer
  '\'_Escape
  'sin'_CommandName
  '\'_Escape
  'theta'_CommandName
  '$'_MathSwitch

See https://tex.stackexchange.com/a/74354 for a complete list of all special LaTeX spacing commands inside and outide of math mode.

No urgency to fix this --- perhaps it is even a feature, since prevents users from trying to override default LaTeX spacing behaviour :)

ivanistheone avatar Oct 18 '20 05:10 ivanistheone

This is done outside of math mode as well, generally to get a space after a macro. This is causing the same problems there.

masonproffitt avatar Dec 03 '21 21:12 masonproffitt

Here's another example of where space gets munged: Notice the space after \toprule

TexSoup(r'''
\begin{document}
  \begin{tabular}{ll}
    \toprule
    {\(a\)} & \\
    \bottomrule
  \end{tabular}%
\end{document}
''')
\begin{document}
  \begin{tabular}{ll}
    \toprule{\(a\)} & \\
    \bottomrule \bot
  \end{tabular}%
\end{document}

astromancer avatar Jun 01 '22 16:06 astromancer