0

How might one treat hyphens as hyphens (not minus) in in-line math?

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{parskip}
\renewcommand\familydefault\sfdefault
\usepackage[nominus]{mathastext}
\mathchardef\hy="2D %% https://tex.stackexchange.com/a/199504/187997
\begin{document}
\begin{enumerate}
\item $Hyphenated-text-string$

\item $Hyphenated\hy{}text\hy{}string$ \end{enumerate} \end{document}

Hyphenated text string

Item 1 treats the hyphen as a minus and replaces the hyphen by an en-dash with extra spacing.

Item 2 achieves what I need by adapting this answer.

I am using in-line math with Bmatrix*, bmatrix*, vmatrix* (for stacking and alignment), left and right braces and brackets, to express the syntax [metalanguage] of COBOL. If possible, I would prefer not having to change the hyphens in hundreds of places, particularly since minus is rarely used in the syntax of the full language.

I was rather hoping that [nominus] would do what I want, but appears to have no effect. Also, [noendash] leaves an unwanted gap.

The log shows:

Package: mathastext 2019/11/16 v1.3w Use the text font in math mode (JFB)

The proposed solution at Hyphens in mathmode, though close, involves wrapping hyphenated text inside a math font style, which, when using mathastext, I have no need to do.

If there is no way to re-configure mathastext, one solution, if possible, is to change the character recognized as minus to a character that, for my purposes, will not be used in math mode, such as circumflex ^ or exclamation !.


While the answer given in a comment works, it is important to note that without [nominus] each hyphen will be changed to an en-dash; thus, the two statements must be used together, as shown below, to prevent the hyphens from being changed.

\usepackage[nominus]{mathastext}
\DeclareMathSymbol{-}{\mathalpha}{operators}{`-}

1 Answers1

1

If you want hyphenated-text-string to appear as italicized text, use \mathit{hyphenated-text-string}, or \textnormal{\itshape hyphenated-text-string} if you have \mathit set to a font other than the one you want.

If you want upright letters, instead use \mathrm or \textnormal. You could also insert other text-mode commands, such as \textnormal{\scshape hyphenated-text} for small caps.

Note that \textnormal prevents the formatting of the surrounding text from bleeding through into math mode, but in some situations, you might want that: for example, you might want to match the formatting of the text around it if you use the expression in a heading. If so, use \text from amsmath instead.

Davislor
  • 44,045
  • I don't use italics or bold in math mode for this document, only the occasional \underline{KEY-WORD}, which may occur in text or math mode. – Rick Smith Jul 08 '20 at 19:49
  • @RickSmith Edited. – Davislor Jul 08 '20 at 20:05
  • I already get upright letters with mathastext. While \textnormal works, it requires that I wrap every hyphenated text string. It's a bit easier to do a Search/Replace - with \hy{} for the hyphenated text; that is, TeXstudio doesn't have a clickable font style for \textnormal, but does have clickable Search/Replace. That is what I have been doing. – Rick Smith Jul 08 '20 at 20:45
  • @RickSmith I would recommend that you create a macro for hyphenated words you use repeatedly in math mode. – Davislor Jul 08 '20 at 20:49