I found this post in the last few days while searching for an answer to the same problem. I'm also using XeLaTeX, and also need fontspec
, so I feel your pain. I tried all kinds of things, which I won't list here.
Here's the solution I came up with:
As you discovered, the Mapping=tex-text
option is what is changing the straight quotes to curly (no matter what). As you also saw, removing it results in no curly quotes anywhere. That's no good either.
The standard XeLaTeX template in TeXShop (I've excluded the sans and mono font declarations) has:
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont[Mapping=tex-text]{Hoefler Text}
I decided to define a new font, using the same typeface as the roman font, but not include any mapping.
\newfontfamily{\S}{Hoefler Text}
As a final step, the \defaultfontfeatures{Mapping=tex-text}
line must be deleted or commented out. If not, it adds mapping to all font declarations. I suppose that's meant to be helpful in case one forgets it, but in this case, it's holding us back. Since \setromanfont
above already declared its mapping, removing it as a default feature won't alter the appearance of normal typing, giving you access to curly quotes.
The altered preamble section will then be:
\usepackage{fontspec,xltxtra,xunicode}
%\defaultfontfeatures{Mapping=tex-text}
\setmainfont[Mapping=tex-text]{Hoefler Text}
\newfontfamily{\S}{Hoefler Text}
When you need straight quotes, put them within the custom font call. Since there is no mapping, you will get finally them.
The ``antique'' table is 5{\S '}6{\S "} long.
I set custom commands to make writing easier.
\newcommand{\inch}{{\S "}}
\newcommand{\feet}{{\S '}}
This allows me to write:
The ``antique'' table is 5\feet 6\inch\ long.
I hope this helps. I was creating a 100+ page document, and needed both curly and straight quotes frequently. This is the only thing I've tried that works, period. If there is a more elegant way (in XeLaTeX with fontspec
), I'd love to learn it. I've only been using TeX/XeLaTeX for 2-3 months, so I'm kind of a newbie.
Here's one solution using TikZ
which defines a new environment using the framed
package. You should preferably compile this with xelatex
or lualatex
, since it gives the easiest access to a wide range of fonts. I've added code to make it run under pdflatex
as well.
The code has now been updated to allow some flexibility in the formatting of the different components of the quotation, and the environment takes two arguments:
Environment Syntax
\begin{shadequote}[<alignment>]{<author>}
text of quote
\end{shadequote}
Code
% !TEX TS-program = xeLaTeX
\documentclass[12pt]{article}
\usepackage{ifxetex,ifluatex}
\usepackage{etoolbox}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usepackage{framed}
% conditional for xetex or luatex
\newif\ifxetexorluatex
\ifxetex
\xetexorluatextrue
\else
\ifluatex
\xetexorluatextrue
\else
\xetexorluatexfalse
\fi
\fi
%
\ifxetexorluatex%
\usepackage{fontspec}
\usepackage{libertine} % or use \setmainfont to choose any font on your system
\newfontfamily\quotefont[Ligatures=TeX]{Linux Libertine O} % selects Libertine as the quote font
\else
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{libertine} % or any other font package
\newcommand*\quotefont{\fontfamily{LinuxLibertineT-LF}} % selects Libertine as the quote font
\fi
\newcommand*\quotesize{60} % if quote size changes, need a way to make shifts relative
% Make commands for the quotes
\newcommand*{\openquote}
{\tikz[remember picture,overlay,xshift=-4ex,yshift=-2.5ex]
\node (OQ) {\quotefont\fontsize{\quotesize}{\quotesize}\selectfont``};\kern0pt}
\newcommand*{\closequote}[1]
{\tikz[remember picture,overlay,xshift=4ex,yshift={#1}]
\node (CQ) {\quotefont\fontsize{\quotesize}{\quotesize}\selectfont''};}
% select a colour for the shading
\colorlet{shadecolor}{Azure}
\newcommand*\shadedauthorformat{\emph} % define format for the author argument
% Now a command to allow left, right and centre alignment of the author
\newcommand*\authoralign[1]{%
\if#1l
\def\authorfill{}\def\quotefill{\hfill}
\else
\if#1r
\def\authorfill{\hfill}\def\quotefill{}
\else
\if#1c
\gdef\authorfill{\hfill}\def\quotefill{\hfill}
\else\typeout{Invalid option}
\fi
\fi
\fi}
% wrap everything in its own environment which takes one argument (author) and one optional argument
% specifying the alignment [l, r or c]
%
\newenvironment{shadequote}[2][l]%
{\authoralign{#1}
\ifblank{#2}
{\def\shadequoteauthor{}\def\yshift{-2ex}\def\quotefill{\hfill}}
{\def\shadequoteauthor{\par\authorfill\shadedauthorformat{#2}}\def\yshift{2ex}}
\begin{snugshade}\begin{quote}\openquote}
{\shadequoteauthor\quotefill\closequote{\yshift}\end{quote}\end{snugshade}}
\begin{document}
\begin{shadequote}[l]{Douglas Adams}
A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
\end{shadequote}
\begin{shadequote}[r]{Douglas Adams}
A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
\end{shadequote}
\begin{shadequote}[c]{Douglas Adams}
A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
\end{shadequote}
\begin{shadequote}{}
A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
\end{shadequote}
\end{document}
In this code, the font for the quotation marks is set independently of the main document font. This is because depending on the main font you choose, the very large quotation marks will not look good; Linux Libertine has pretty quotes that seem appropriate for the purpose. If you want to use this environment with another main document font, remove/change the \usepackage{libertine}
.
Sample output
![output of code](https://i.stack.imgur.com/fKf5A.png)
Best Answer
One option is to use the
\textquotesingle
from thetextcomp
package as this: