3

I need to write a text which contains some math symbols. In detail those include \rightarrow, \forall and \exists. I know I can switch into math mode with the $ symbol, but I have quite a lot of text and I do not want em in italic like it is default for math mode.

I am just curious what is the right way to go. Shall I switch to math mode for every symbol and try to make the math mode "non-italic" or is there a better way like with the Greek symbols the \textalpha, etc. from the textgreek package?

Here is an example line from my text:

(S.Sname, B.Bname): ∀S ∃A ∃B (S.AId = A.AId \& B.BId = A.BId \& S.Sduration > 300)
3
  • If you use XeLaTeX and a font that contains these symbols (DejaVu Sans, for instance), you can compile as is.
    – Bernard
    Jun 10, 2015 at 18:06
  • @lenxn you can use \text command into equatios for comments or words. That text not appears in italic. Example: $\forall x,\;\exists y\text{ such that }$. I don't remember if you will need amsmath to use that command.
    – juanuni
    Jun 10, 2015 at 22:20
  • I'm not clear what you want not to be italic. Could you please provide a compilable example and say what you want to be different? The symbols you mention are not italicised, are they? (And nothing in maths mode is \em or \emph, if 'em' is not a typo for 'them'.)
    – cfr
    Mar 21, 2018 at 0:49

2 Answers 2

5

You could use this little snippet which defines \textify. The control sequence \textify takes another control sequence (for instance \exists) and wraps it into \ensuremath{…}.

I don't think that one needs to go through all the \GlobalLetLtxMacro and \protected\gdef hassle for simple things like \exists, which is only a \mathchar, but this should cover all weird edge cases.

N.B.: The \macro in \textify\macro may not take any mandatory arguments. Optional arguments will output as their default value. If the macro you want to textify needs any arguments a more complicated approach is needed.

\documentclass{article}
\usepackage{letltxmacro}
\newcommand\textify[1]{%
  \expandafter\GlobalLetLtxMacro\csname textify@\string#1\endcsname#1%
  \protected\gdef#1{\ensuremath{\csname textify@\string#1\endcsname}}%
}

\textify\exists
\textify\forall
\begin{document}
\exists $\exists$

\forall $\forall$
\end{document}

enter image description here

For reference, a non-letltxmacro and non-protected version of \textify would read

\newcommand\textify[1]{%
  \global\expandafter\let\csname textify@\string#1\endcsname#1%
  \gdef#1{\ensuremath{\csname textify@\string#1\endcsname}}%
}

which of course doesn't require the letltxmacro package.

0

Redefine each of the symbols with \ensuremath so they always use math mode. To avoid an infinite \ensuremath{\ensuremath{\ensuremath... loop, save the old command with \let to use it in the new definition.

For example, to redefine \to (it's the same symbol as \rightarrow):

\let\OLDto\to
\renewcommand{\to}{\ensuremath{\OLDto}}

Now you can use \to in text mode! Read more here. Write \to\ if you want the following space to not be eaten.

1
  • 1
    Basically, it is the same approach as in Henri Menke's answer. However, I would use a "better let" as provided by package 1etltxmacro. Quite some math symbols are defined by \DeclareRobustCommand (e.g. \notin, \Longrightarrow). Then, saving the old meaning in a new macro is more complicate, because two commands needs to be redefined to avoid trouble in some contexts. Mar 21, 2018 at 4:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .