41

How do I produce the prime symbol in text mode? In math mode the prime symbol is produced by ' but in text mode it produces something else.

38

If you really want the math prime symbol you may simply use $'$ or $\prime$, or if you want to use it in text and math mode \ensuremath{'} or \ensuremath{\prime}, e.g.:

\documentclass{article}
\newcommand*{\everymodeprime}{\ensuremath{\prime}}
\begin{document}
Prime in text mode: \everymodeprime

Prime in math mode: $\everymodeprime$
\end{document}

I've used \prime instead of ' to avoid typo mistakes.

\ensuremath does only switch to math mode, if math mode it not already active. So it is often useful to define commands, that uses math mode commands and should work in text and math mode.

17

The flexisym package offers \textprime which can be directly used in math or in text mode:

\documentclass{article}
\usepackage{flexisym}

\begin{document}

a\textprime

$a\textprime$

\end{document}

enter image description here

11

I don't think there's a \prime character in text mode. If you want an upright single quote, you can use \textquotesingle defined in the textcomp package; alternatively if you actually want a prime, then you can just use $'$ in text mode.

  • I want an actual prime but I don't want to go via inline math mode. – N.N. Nov 30 '11 at 14:12
  • 1
    N.N.: Why not, if this is the character you want, but \textquotesingle, \textquoteleft, and \textquoteright aren't? – Schweinebacke Nov 30 '11 at 14:22
  • @Schweinebacke I want to use prime in list labels and then refer to the list items from math mode but that seems to force me to nest math modes which leads to errors, see tex.stackexchange.com/questions/36658/…. – N.N. Nov 30 '11 at 14:27
  • 1
    The flexisym package defines \textprime: \DeclareRobustCommand\textprime{\leavevmode \raise.8ex\hbox{\text@char\scriptfont\prime}% } – Gonzalo Medina Nov 30 '11 at 14:35
  • 2
    N.N.: \ensuremath{'} may be used to nest math, because it switchs to math only if your are not in math mode already. – Schweinebacke Nov 30 '11 at 15:15
4

Using flexisym requires subduing to its weird decision about several symbols.

It's much simpler to use

\documentclass{article}

\makeatletter
\DeclareTextCommand{\textprime}{\encodingdefault}{%
  \mbox{$\m@th'\kern-\scriptspace$}% 
}
\makeatother

\begin{document}

a\textprime{} b

$a\textprime$

\end{document}

With \DeclareTextCommand we disallow using the symbol in math mode (a warning will be produced); with \mbox we avoid an error, if \textprime is issued in math mode nonetheless; with \m@th we nullify a possible nonzero value of \mathsurround; with \kern-\scriptspace we remove the kerning that's added after subscripted or superscripted math atoms.

enter image description here

1

In Unicode, prime is ′ (U+2032). You can use it with fontspec if your text font supports it. The result probably won’t match prime in math mode.

\documentclass[varwidth]{standalone}
\usepackage{fontspec}
\usepackage{libertine}

\newcommand\textprime{\char"2032}

\begin{document}

30\textprime

\end{document}

Libertine font sample

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.