0

Consider the following MWE:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
we have $\sigma_V$, $\sigma_\text{V}$, but $\sigma_\text{\scriptsize v}$
\end{document}

This produces a warning (using pandoc.exe .\mwe.tex -o mwe.docx,

    [WARNING] Could not convert TeX math \sigma_\text{\scriptsize v}, rendering as TeX:
    \sigma_\text{\scriptsize v}
                 ^
    unexpected "\\"
    expecting "}", text, "{", "$", "$$", "\\(" or "\\[" 

Correspondingly, the docx output is enter image description here

Now, in Pandoc LaTeX to .docx, change font size the answer states that pandoc doesn't recognise \scriptsize (and other) commands. Is there a way to

  1. make pandoc understand those, or
  2. make pandoc ignore them?

(In my application, the font size commands show up mostly in subscripts. Ignoring them which is something I could live with for the word output, whcih is for sharing with colleagues, but not in the LaTeX source. If it helps, most instances of the form \sigma_\text{\scriptsize v} appear in defined \newcommands, so maybe pandoc can use its own newcomamnds without the \scriptsize(?).)

  • 1
    \sigma_\text{\scriptsize v} is (1) dangerous andf (2) \scriptsize is a math command and the argument to \text is text not math. \sigma_{v} would give the same. a_\text{...} is just plain wrong and should never be used. It is pure change that it actually works. – daleif Dec 02 '22 at 09:27
  • 1
    s/change/chance/ ? – Thruston Dec 02 '22 at 09:31
  • @daleif (1) why is it dangerous? (2)\scriptsize is text mode command (unlike \scriptstyle), and the output of\sigma_\text{\scriptsize v}is obviously different from \sigma_v. (3) What is wrong about a_\text{...}? – user104694 Dec 02 '22 at 09:34
  • there is no reason to expect x_\text{...}to work, it does due to low level parsing weirdness if you use a full tex parser but it is not latex syntax, it shoud be x_{\text{...}} also x_{\mathrm{...}} is almost always preferable as it uses the fonts specified for math – David Carlisle Dec 02 '22 at 09:50
  • @DavidCarlisle OK; good to know; I have been using x_\text{...} since forever. Should I expect it to stop working at any point? (I would have to rewrite all my old files...) – user104694 Dec 02 '22 at 10:11
  • 1
    @Toffomat unfortunately we probably can not make it stop working even though it has never been supported and is just such a weird syntax. Several latex to whatever convertors fail on it. Any reasonable parser would have _ parse like a macro argument \fbox\text{x} is \fbox{\text}{x} and an error. _\text{x} is not _{\text}{x} it magically braces itself and expands to _{\text{x}} and "works" but if you have that in a document I'd use an editor to fix the markup. – David Carlisle Dec 02 '22 at 10:19
  • sed -i '' s/_\\text/_\\mathrm/g *.tex ? – Thruston Dec 02 '22 at 11:37
  • @Thruston I want to keep the text, but would have to add curly braces around the subscript. If I have to, I will try to cook up a regular expression... – user104694 Dec 02 '22 at 11:52

1 Answers1

1

Assuming you want upright roman subscripts, then it would be better to say so explicitly in the markup:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
we have $\sigma_V$, $\sigma_{\mathrm{V}}$, but $\sigma_{\mathrm{v}}$
\end{document}

This produces exactly the same PDF as the MWE, but also seems to work ok with Pandoc.

To get even smaller subscripts, then stick with math sizing:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
we have $\sigma_V$, $\sigma_{\mathrm{V}}$, but $\sigma_{\scriptscriptstyle\mathrm{v}}$
\end{document}

This also appears to work with Pandoc.

Thruston
  • 42,268
  • Unfortunately, that doesn't work: I want smaller upright roman subscripts. The \text{...} command works fine, it is the \scriptsize that causes the problem (also inside \mathrm{}). – user104694 Dec 02 '22 at 09:37
  • See edits to answer – Thruston Dec 02 '22 at 09:41
  • @Toffomat \text is the wrong markup if you want upright roman, it gives you the current text font active before the math started, so for example it is typically italic if the math is in a theorem. If you do use \text in a subscript , it is automatically scriptsize, so \scriptsize does nothing – David Carlisle Dec 02 '22 at 09:56
  • 1
    It is still wrong to write v\sigma_\mathrm{v}, as David mentions there is no reason for it to keep working, please always use \sigma_{\mathrm{v}} then inexperienced users don't get into bad habits. – daleif Dec 02 '22 at 10:02
  • @DavidCarlisle Right, I missed that it's automatically scriptsize, but the problem is the same with \tiny – user104694 Dec 02 '22 at 10:06
  • @DavidCarlisle I was also a bit sloppy: I do want the subscript in the curent text font. In particular, on a slide I would want the subscript in sans (as the text is). So \text{}works better for me than \mathrm{} – user104694 Dec 02 '22 at 10:09
  • In any case, the answer solves the problem in – user104694 Dec 02 '22 at 10:10
  • @Toffomat use math commands for fonts in math, so \mathrm and if you must, \scriptscriptstyle as in the answer here. \tiny is a text font command – David Carlisle Dec 02 '22 at 10:10
  • @DavidCarlisle Is there anything technically wrong with $x \text{a\tiny b} y$? (I'm regularly using stuff like \epsilon_{\text{\tiny M}} because uper case subsripts are too big for lower case Greek letters.) – user104694 Dec 02 '22 at 10:14
  • It is logically dubious to be using text fonts. In the default setup it happens that the roman math font is the text font but they are declared separately and not necessarily the same. It's also somewhat inefficient as \text has to switch out of math, typeset the content in 4 styles, then pick the style needed and insert in to the math list. @Toffomat – David Carlisle Dec 02 '22 at 10:24
  • @DavidCarlisle In my view, the subscripts which are not mathematical (i.e. stuff like k_effective, M_Planck etc as opposed to indices, powers, transpose etc.) feel texty, so I'd like them to be e.g. sans-serif if the text is, and switching between e.g. \mathsf and \mathrm is cumbersome and error-prone. So \textdoes exactly what I need -- is there a way that is more in line with LaTeX internal structure? – user104694 Dec 02 '22 at 10:41