Skip to content

Commit

Permalink
LaTeX writer: Use fixltx2e package to provide '\textsubscript'.
Browse files Browse the repository at this point in the history
  • Loading branch information
John MacFarlane committed Apr 21, 2012
1 parent 9a347c3 commit 869ff43
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
10 changes: 2 additions & 8 deletions src/Text/Pandoc/Writers/LaTeX.hs
Expand Up @@ -56,7 +56,6 @@ data WriterState =
, stEnumerate :: Bool -- true if document needs fancy enumerated lists
, stTable :: Bool -- true if document has a table
, stStrikeout :: Bool -- true if document has strikeout
, stSubscript :: Bool -- true if document has subscript
, stUrl :: Bool -- true if document has visible URL link
, stGraphics :: Bool -- true if document contains images
, stLHS :: Bool -- true if document has literate haskell code
Expand All @@ -75,7 +74,7 @@ writeLaTeX options document =
WriterState { stInNote = False, stInTable = False,
stTableNotes = [], stOLLevel = 1, stOptions = options,
stVerbInNote = False, stEnumerate = False,
stTable = False, stStrikeout = False, stSubscript = False,
stTable = False, stStrikeout = False,
stUrl = False, stGraphics = False,
stLHS = False, stBook = writerChapters options,
stCsquotes = False, stHighlighting = False,
Expand Down Expand Up @@ -148,7 +147,6 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
[ ("fancy-enums", "yes") | stEnumerate st ] ++
[ ("tables", "yes") | stTable st ] ++
[ ("strikeout", "yes") | stStrikeout st ] ++
[ ("subscript", "yes") | stSubscript st ] ++
[ ("url", "yes") | stUrl st ] ++
[ ("numbersections", "yes") | writerNumberSections options ] ++
[ ("lhs", "yes") | stLHS st ] ++
Expand Down Expand Up @@ -503,11 +501,7 @@ inlineToLaTeX (Strikeout lst) = do
inlineToLaTeX (Superscript lst) =
inlineListToLaTeX lst >>= return . inCmd "textsuperscript"
inlineToLaTeX (Subscript lst) = do
modify $ \s -> s{ stSubscript = True }
contents <- inlineListToLaTeX lst
-- oddly, latex includes \textsuperscript but not \textsubscript
-- so we have to define it (using a different name so as not to conflict with memoir class):
return $ inCmd "textsubscr" contents
inlineListToLaTeX lst >>= return . inCmd "textsubscript"
inlineToLaTeX (SmallCaps lst) =
inlineListToLaTeX lst >>= return . inCmd "textsc"
inlineToLaTeX (Cite cits lst) = do
Expand Down
2 changes: 1 addition & 1 deletion templates
Submodule templates updated 2 files
+1 −3 default.beamer
+1 −3 default.latex
1 change: 1 addition & 0 deletions tests/lhs-test.latex
@@ -1,6 +1,7 @@
\documentclass[]{article}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifxetex
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
Expand Down
1 change: 1 addition & 0 deletions tests/lhs-test.latex+lhs
@@ -1,6 +1,7 @@
\documentclass[]{article}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifxetex
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
Expand Down
5 changes: 3 additions & 2 deletions tests/writer.latex
@@ -1,6 +1,7 @@
\documentclass[]{article}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifxetex
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
Expand Down Expand Up @@ -54,7 +55,6 @@
\usepackage[normalem]{ulem}
% avoid problems with \sout in headers with hyperref:
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
\newcommand{\textsubscr}[1]{\ensuremath{_{\scriptsize\textrm{#1}}}}
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em} % prevent overfull lines
Expand Down Expand Up @@ -596,7 +596,8 @@ This is code: \texttt{\textgreater{}}, \texttt{\$}, \texttt{\textbackslash{}},
Superscripts: a\textsuperscript{bc}d a\textsuperscript{\emph{hello}}
a\textsuperscript{hello~there}.

Subscripts: H\textsubscr{2}O, H\textsubscr{23}O, H\textsubscr{many~of~them}O.
Subscripts: H\textsubscript{2}O, H\textsubscript{23}O,
H\textsubscript{many~of~them}O.

These should not be superscripts or subscripts, because of the unescaped
spaces: a\^{}b c\^{}d, a\textasciitilde{}b c\textasciitilde{}d.
Expand Down

0 comments on commit 869ff43

Please sign in to comment.