aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MANUAL.txt5
-rw-r--r--data/templates/default.latex3
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs25
-rw-r--r--src/Text/Pandoc/Writers/LaTeX/Types.hs2
4 files changed, 34 insertions, 1 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index c7ffdbd6f..39fbeb61c 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -156,7 +156,9 @@ packages are used if available, and [`csquotes`] will be used
for [typography] if the `csquotes` variable or metadata field is
set to a true value. The [`natbib`], [`biblatex`], [`bibtex`],
and [`biber`] packages can optionally be used for [citation
-rendering]. The following packages will be used to improve
+rendering]. If math with `\cancel`, `\bcancel`, or `\xcancel`
+is used, the [`cancel`] package is needed.
+The following packages will be used to improve
output quality if present, but pandoc does not require them to
be present: [`upquote`] (for straight quotes in verbatim
environments), [`microtype`] (for better spacing adjustments),
@@ -182,6 +184,7 @@ better line breaks in URLs), and [`footnotehyper`] or
[`framed`]: https://ctan.org/pkg/framed
[`geometry`]: https://ctan.org/pkg/geometry
[`graphicx`]: https://ctan.org/pkg/graphicx
+[`cancel`]: https://ctan.org/pkg/cancel
[`hyperref`]: https://ctan.org/pkg/hyperref
[`iftex`]: https://ctan.org/pkg/iftex
[`listings`]: https://ctan.org/pkg/listings
diff --git a/data/templates/default.latex b/data/templates/default.latex
index b008d3db2..bbf84752a 100644
--- a/data/templates/default.latex
+++ b/data/templates/default.latex
@@ -24,6 +24,9 @@ $if(geometry)$
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
$endif$
\usepackage{amsmath,amssymb}
+$if(cancel)$
+\usepackage{cancel}
+$endif$
$--
$-- section numbering
$--
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 2c71e689a..fe549ad17 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -65,8 +65,11 @@ import Text.Pandoc.Writers.LaTeX.Util (stringToLaTeX, StringContext(..),
wrapDiv, hypertarget, labelFor,
getListingsLanguage, mbBraced)
import Text.Pandoc.Writers.Shared
+import qualified Data.Attoparsec.Text as A
import qualified Text.Pandoc.UTF8 as UTF8
import qualified Text.Pandoc.Writers.AnnotatedTable as Ann
+import Data.Char (isLetter)
+import Control.Applicative ((<|>))
-- Work around problems with notes inside emphasis (see #8982)
isolateBigNotes :: ([Inline] -> Inline) -> [Inline] -> [Inline]
@@ -229,6 +232,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
defField "verbatim-in-note" (stVerbInNote st) $
defField "tables" (stTable st) $
defField "multirow" (stMultiRow st) $
+ defField "cancel" (stCancel st) $
defField "strikeout" (stStrikeout st) $
defField "url" (stUrl st) $
defField "numbersections" (writerNumberSections options) $
@@ -1029,11 +1033,13 @@ inlineToLaTeX (Str str) = do
inlineToLaTeX (Math _ str)
| isMathEnv str -- see #9711
= do setEmptyLine False
+ when (needsCancel str) $ modify $ \st -> st{ stCancel = True }
pure $ literal str
inlineToLaTeX (Math InlineMath str) = do
setEmptyLine False
inSoul <- gets stInSoulCommand
let contents = literal (handleMathComment str)
+ when (needsCancel str) $ modify $ \st -> st{ stCancel = True }
return $
if inSoul -- #9597
then "$" <> contents <> "$"
@@ -1042,6 +1048,7 @@ inlineToLaTeX (Math DisplayMath str) = do
setEmptyLine False
inSoul <- gets stInSoulCommand
let contents = literal (handleMathComment str)
+ when (needsCancel str) $ modify $ \st -> st{ stCancel = True }
return $
if inSoul -- # 9597
then "$$" <> contents <> "$$"
@@ -1339,3 +1346,21 @@ isMathEnv t =
, "eqnarray"
, "displaymath"
]
+
+-- True if the math needs the cancel package
+needsCancel :: Text -> Bool
+needsCancel t =
+ case A.parseOnly pCancel t of
+ Right True -> True
+ _ -> False
+ where
+ pCancel = (False <$ A.endOfInput) <|> do
+ c <- A.anyChar
+ case c of
+ '\\' -> do
+ x <- A.takeWhile isLetter
+ if x == "cancel" || x == "xcancel" || x == "bcancel"
+ then return True
+ else pCancel
+ _ -> pCancel
+
diff --git a/src/Text/Pandoc/Writers/LaTeX/Types.hs b/src/Text/Pandoc/Writers/LaTeX/Types.hs
index 2477c2fa7..1295d2d01 100644
--- a/src/Text/Pandoc/Writers/LaTeX/Types.hs
+++ b/src/Text/Pandoc/Writers/LaTeX/Types.hs
@@ -53,6 +53,7 @@ data WriterState =
, stIsFirstInDefinition :: Bool -- ^ first block in a defn list
, stLang :: Maybe Lang -- ^ lang specified in metadata
, stInSoulCommand :: Bool -- ^ in a soul command like ul
+ , stCancel :: Bool -- ^ true if document uses \cancel
}
startingState :: WriterOptions -> WriterState
@@ -93,4 +94,5 @@ startingState options =
, stIsFirstInDefinition = False
, stLang = Nothing
, stInSoulCommand = False
+ , stCancel = False
}