Display real apostrophe in parts of a document

The question How to make a real apostrophe or single-quote in LaTeX is my question too, but the answer points to a package upquote that affects the entire document. I need to display an apostrophe (U+0027) only a couple of times within the document. Otherwise I would like the general conversion to quote to take place.

\documentclass{article}
\usepackage{fontspec, xunicode, xltxtra}
\defaultfontfeatures{Mapping = tex-text}

\begin{document}
\noindent I would like an apostrophe to appear in the word ap'ple (U+0027), but a right quotation mark (U+2019) when I quote the word orange'.
\end{document}


-
So you actually want in some places to not have the typographically right apostrophe/right quotation mark (U+2019) but the vertical typewriter apostrophe ' (U+0027, the one that you get by hitting the ' key, which is the one that appears in the input)? How should LaTeX distinct between the two types of input? –  Qrrbrbirlbel Feb 24 '13 at 21:09
@Qrrbrbirlbel: Presumably by having two distinct inputs ... –  Sverre Feb 25 '13 at 12:06

Solution 1: Markup for quotations

One simple way to do this would be to not use the Mapping=text-tex (which, BTW has been replaced with the Ligatures=TeX option) and use the csquotes package to manage your quoting. Here's an example:

% !TEX TS-program = XeLaTeX
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\usepackage{csquotes}
\MakeOuterQuote{"}

\begin{document}
\noindent I would like an apostrophe to appear in the word ap'ple (U+0027), but a
right proper quotations marks (U+2019) when I quote a word with double quotes:
\enquote{orange} or single quotes: \enquote*{orange} or double quotes using the
"Active Quotes" function of the package.
\end{document}


Solution 2: Define an apostrophe font and markup

Another way would be to load your font twice, once using the Ligatures=TeX and the other without, and then define markup for the apostrophe.

% !TEX TS-program = XeLaTeX
\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\quotefont{Linux Libertine O}
\newcommand{\apostrophe}{{\quotefont'}} % or just use {\quotefont text}

\begin{document}
\noindent I would like an apostrophe to appear in the word ap\apostrophe ple
(U+0027), or {\quotefont ap'ple} but a right proper quotations marks (U+2019) when I
quote a word with double quotes: orange'' or single quotes: orange'.
\end{document}


In this solution, the markup for the apostrophe isn't actually necessary, since any text that is grouped with {\quotefont ... } will use the single quote as typed.

-
Both of these solutions seem to be perfect. In my specific scenario, however, it turns out that your pointing out the Ligatures=TeX is all I need, because in the cases I need the apostrophe to appear as an apostrophe, the font is not my main font, so I can just not include Ligatures=TeX as an option in my \newfontfamily\coolfont\{Name of my cool font} call. –  Sverre Feb 25 '13 at 12:41
Another, and perhaps the easiest, solution is given in tex.stackexchange.com/questions/103076/… –  Sverre Mar 20 '13 at 15:38
@Sverre The Mapping solution only works for XeLaTeX and can't be extended to LuaLaTeX, though. –  Alan Munn Mar 20 '13 at 18:37

Another method (I got the idea from reading 2 Font commands in the XeTeX reference (texdoc xetexref)):

\documentclass{article}
\usepackage{fontspec}
\usepackage{libertine}

\newcommand{\apostrophe}{\XeTeXglyph\XeTeXcharglyph"0027\relax}

\begin{document}
\noindent I would like an apostrophe to appear in the word ap\apostrophe ple
(U+0027) but a right proper quotations marks (U+2019) when I
quote a word with double quotes: orange'' or single quotes: orange'.
\end{document}
`

Here is the result (also tested ok with other fonts):

-