git.iko.soy/typeable/pandoc
on master help sign in
Texinfo writer: use @sup and @sub instead of custom macros

Fixes #4728

commitebf4ed89440d459684e2becad06a34ac3cdba7d5 authorAlexander Krotov <ilabdsf@gmail.com> dateMon 25 Jun 2018, 03:14 (8 years ago) parentdda3882
3 files changed+5−54
data/templates/default.texinfo−22 src/Text/Pandoc/Writers/Texinfo.hs+3−10 test/writer.texinfo+2−22
data/templates/default.texinfo−22
@@ -9,28 +9,6 @@ $if(strikeout)$
99~~\text\~~
1010@end macro
1111
12−$endif$
13−$if(subscript)$
14−@macro textsubscript{text}
15−@iftex
16−@textsubscript{\text\}
17−@end iftex
18−@ifnottex
19−_@{\text\@}
20−@end ifnottex
21−@end macro
22−
23−$endif$
24−$if(superscript)$
25−@macro textsuperscript{text}
26−@iftex
27−@textsuperscript{\text\}
28−@end iftex
29−@ifnottex
30−^@{\text\@}
31−@end ifnottex
32−@end macro
33−
3412$endif$
3513@ifnottex
3614@paragraphindent 0
src/Text/Pandoc/Writers/Texinfo.hs+3−10
@@ -56,8 +56,6 @@ import Text.Printf (printf)
5656
5757data WriterState =
5858 WriterState { stStrikeout :: Bool -- document contains strikeout
59− , stSuperscript :: Bool -- document contains superscript
60− , stSubscript :: Bool -- document contains subscript
6159 , stEscapeComma :: Bool -- in a context where we need @comma
6260 , stIdentifiers :: Set.Set String -- header ids used already
6361 , stOptions :: WriterOptions -- writer options
@@ -74,8 +72,7 @@ type TI m = StateT WriterState m
7472writeTexinfo :: PandocMonad m => WriterOptions -> Pandoc -> m Text
7573writeTexinfo options document =
7674 evalStateT (pandocToTexinfo options $ wrapTop document)
77− WriterState { stStrikeout = False, stSuperscript = False,
78− stEscapeComma = False, stSubscript = False,
75+ WriterState { stStrikeout = False, stEscapeComma = False,
7976 stIdentifiers = Set.empty, stOptions = options}
8077
8178-- | Add a "Top" node around the document, needed by Texinfo.
@@ -102,8 +99,6 @@ pandocToTexinfo options (Pandoc meta blocks) = do
10299 let context = defField "body" body
103100 $ defField "toc" (writerTableOfContents options)
104101 $ defField "titlepage" titlePage
105− $ defField "subscript" (stSubscript st)
106− $ defField "superscript" (stSuperscript st)
107102 $
108103 defField "strikeout" (stStrikeout st) metadata
109104 case writerTemplate options of
@@ -427,14 +422,12 @@ inlineToTexinfo (Strikeout lst) = do
427422 return $ text "@textstrikeout{" <> contents <> text "}"
428423
429424inlineToTexinfo (Superscript lst) = do
430− modify $ \st -> st{ stSuperscript = True }
431425 contents <- inlineListToTexinfo lst
432− return $ text "@textsuperscript{" <> contents <> char '}'
426+ return $ text "@sup{" <> contents <> char '}'
433427
434428inlineToTexinfo (Subscript lst) = do
435− modify $ \st -> st{ stSubscript = True }
436429 contents <- inlineListToTexinfo lst
437− return $ text "@textsubscript{" <> contents <> char '}'
430+ return $ text "@sub{" <> contents <> char '}'
438431
439432inlineToTexinfo (SmallCaps lst) =
440433 inlineListToTexinfo lst >>= return . inCmd "sc"
test/writer.texinfo+2−22
@@ -5,24 +5,6 @@
55~~\text\~~
66@end macro
77
8−@macro textsubscript{text}
9−@iftex
10−@textsubscript{\text\}
11−@end iftex
12−@ifnottex
13−_@{\text\@}
14−@end ifnottex
15−@end macro
16−
17−@macro textsuperscript{text}
18−@iftex
19−@textsuperscript{\text\}
20−@end iftex
21−@ifnottex
22−^@{\text\@}
23−@end ifnottex
24−@end macro
25−
268@ifnottex
279@paragraphindent 0
2810@end ifnottex
@@ -738,11 +720,9 @@ This is code: @code{>}, @code{$}, @code{\}, @code{\$}, @code{<html>}.
738720
739721@textstrikeout{This is @emph{strikeout}.}
740722
741−Superscripts: a@textsuperscript{bc}d a@textsuperscript{@emph{hello}}
742−a@textsuperscript{hello@ there}.
723+Superscripts: a@sup{bc}d a@sup{@emph{hello}} a@sup{hello@ there}.
743724
744−Subscripts: H@textsubscript{2}O, H@textsubscript{23}O,
745−H@textsubscript{many@ of@ them}O.
725+Subscripts: H@sub{2}O, H@sub{23}O, H@sub{many@ of@ them}O.
746726
747727These should not be superscripts or subscripts, because of the unescaped
748728spaces: a^b c^d, a~b c~d.