25

How to get the closing single quote in math mode. The apostrophe in math mode is displayed as prime.

\documentclass{article}                                                              
\begin{document}                                                                     
Why can't I get $`a'$ in math mode.                                                  
\end{document}  
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036

3 Answers3

17

Punctuation that is not part of a formula should go outside the formula:

When \(a>0\), we say that \(a\) is \emph{positive}.

In the interval \([0,1]\) there are infinitely many rational numbers.

It's quite rare that quotes are used as math symbols, but I've seen them in some textbook on mathematical logic. Since ' is used for denoting a prime (dash) in math, one can resort to a different trick: the lines

\DeclareMathSymbol{\mlq}{\mathord}{operators}{``}
\DeclareMathSymbol{\mrq}{\mathord}{operators}{`'}

will define two commands that will give left and right quotes in math and your input can become

Why can't I get $\mlq a\mrq$ in math mode.

but in this case `$a$' should be probably better.

I've added a companion to \mrq just for symmetry and, perhaps, greater clarity.

egreg
  • 1,121,712
16

You should switch to text-mode, eg.

\documentclass{article}
\begin{document}
Why can't I get $`a\textrm'$ in math mode
\end{document}
  • I find it is quite a good fix, but one caveat: for some formats you may get inconsistent results. For example, \boldmath $\a\textrm'$`shows the left quote bold, but the second not, because the second is set to standard roman. Just be aware. ;) By the way, egreg's solutions behaves correctly. – loved.by.Jesus Aug 13 '20 at 12:54
  • Can the quote be straight? – alper Apr 20 '22 at 14:26
0

For the sake of completeness. A very flexible method to edit your equations is to step into text mode using the amsmath package command \text{<your text>}. Note that inside the \text command you can open new math environments. For example in the most simple case we might write: $\text{`$a$'}$ .

Admittedly, it looks a bit awkward, but in the example below it feels acceptable.

I also compare the \text solution with the \mathrm solution: \mathrm uses always the roman family (serif), but the function \text adapts the quotes to the family that is being used at the moment, for example sans serif.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

We have equation serif (\text{$a$'}=20\) \(a\textrm'=20) \sffamily We have equation sans (\text{$a$'}=20\) \(a\textrm'=20)

\end{document}

enter image description here