diff options
| -rw-r--r-- | src/Text/Pandoc/Readers/LaTeX/Parsing.hs | 51 | ||||
| -rw-r--r-- | test/command/3983.md | 4 | ||||
| -rw-r--r-- | test/command/4007.md | 2 | ||||
| -rw-r--r-- | test/command/4134.md | 2 | ||||
| -rw-r--r-- | test/command/7434.md | 2 | ||||
| -rw-r--r-- | test/command/macros.md | 3 | ||||
| -rw-r--r-- | test/command/newif.md | 4 | ||||
| -rw-r--r-- | test/latex-reader.native | 2 | ||||
| -rw-r--r-- | test/markdown-reader-more.native | 14 |
9 files changed, 44 insertions, 40 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs index 852b99b4d..6bd5557ac 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs @@ -120,6 +120,7 @@ import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..), import Text.Pandoc.Shared import Text.Parsec.Pos import Text.Pandoc.Walk +import Debug.Trace newtype DottedNum = DottedNum [Int] deriving (Show, Eq) @@ -369,27 +370,27 @@ tokenize = totoks -- to \makeatletter and \makeatother, but this is -- probably best for now let (ws, rest'') = T.span isLetterOrAt rest - (ss, rest''') = T.span isSpaceOrTab rest'' + (ss, rest''') = spanSpaces rest'' + newsp = if T.any (== '\n') ss + then setSourceColumn + (incSourceLine pos 1) + (1 + T.length + (T.takeWhileEnd (/='\n') ss)) + else incSourceColumn pos + (1 + T.length ws + T.length ss) in Tok pos (CtrlSeq ws) ("\\" <> ws <> ss) - : totoks (incSourceColumn pos - (1 + T.length ws + T.length ss)) rest''' + : totoks newsp rest''' | isSpaceOrTab d || d == '\n' -> - let (w1, r1) = T.span isSpaceOrTab rest - (w2, (w3, r3)) = case T.uncons r1 of - Just ('\n', r2) - -> (T.pack "\n", - T.span isSpaceOrTab r2) - _ -> (mempty, (mempty, r1)) - ws = "\\" <> w1 <> w2 <> w3 - in case T.uncons r3 of - Just ('\n', _) -> - Tok pos (CtrlSeq " ") ("\\" <> w1) - : totoks (incSourceColumn pos (T.length ws)) - r1 - _ -> - Tok pos (CtrlSeq " ") ws - : totoks (incSourceColumn pos (T.length ws)) - r3 + let (ss', r1) = spanSpaces rest' + ss = T.singleton d <> ss' + newsp = if T.any (== '\n') ss + then setSourceColumn + (incSourceLine pos 1) + (1 + T.length + (T.takeWhileEnd (/='\n') ss)) + else incSourceColumn pos (1 + T.length ss) + in Tok pos (CtrlSeq " ") ("\\" <> ss) : + totoks newsp r1 | otherwise -> Tok pos (CtrlSeq (T.singleton d)) (T.pack [c,d]) : totoks (incSourceColumn pos 2) rest' @@ -431,6 +432,18 @@ isSpaceOrTab ' ' = True isSpaceOrTab '\t' = True isSpaceOrTab _ = False +-- gobble spaces and at most one newline not followed by a blank line +spanSpaces :: Text -> (Text, Text) +spanSpaces t = + let (a, r1) = T.span isSpaceOrTab t + in case T.uncons r1 of + Just ('\n', r2) -> + let (b, r3) = T.span isSpaceOrTab r2 + in case T.uncons r3 of + Just ('\n', _) -> (a, r1) -- blank line + _ -> (a <> "\n" <> b, r3) + _ -> (a, r1) + isLetterOrAt :: Char -> Bool isLetterOrAt '@' = True isLetterOrAt c = isLetter c diff --git a/test/command/3983.md b/test/command/3983.md index 82c1deef0..3d93a436b 100644 --- a/test/command/3983.md +++ b/test/command/3983.md @@ -5,7 +5,7 @@ \graphicspath\expandafter{\expandafter{\filename@area}}% \makeatother ^D -[ RawBlock (Format "latex") "\\makeatletter" +[ RawBlock (Format "latex") "\\makeatletter\n" , RawBlock (Format "latex") "\\makeatother" ] ``` @@ -17,7 +17,7 @@ \DeclareRobustCommand{\urlfootnote}{\hyper@normalise\urlfootnote@} \makeatother ^D -[ RawBlock (Format "latex") "\\makeatletter" +[ RawBlock (Format "latex") "\\makeatletter\n " , RawBlock (Format "latex") "\\makeatother" ] ``` diff --git a/test/command/4007.md b/test/command/4007.md index 974a88ab9..2529349ff 100644 --- a/test/command/4007.md +++ b/test/command/4007.md @@ -3,7 +3,7 @@ \newcommand\arrow\to $a\arrow b$ ^D -[ Para [ Math InlineMath "a\\to b" ] ] +[ Para [ Math InlineMath "a\\to\nb" ] ] ``` ``` diff --git a/test/command/4134.md b/test/command/4134.md index 195d85129..4b170e6f1 100644 --- a/test/command/4134.md +++ b/test/command/4134.md @@ -20,5 +20,5 @@ Hello.\ World. ^D -[ Para [ Str "Hello.\160" ] , Para [ Str "World." ] ] +[ Para [ Str "Hello.\160World." ] ] ``` diff --git a/test/command/7434.md b/test/command/7434.md index e4f2743a1..a31d3b299 100644 --- a/test/command/7434.md +++ b/test/command/7434.md @@ -11,7 +11,7 @@ ^D [ RawBlock (Format "tex") - "\\begin{proof}\n\\newcommand{\\x}{\\left.\\right.}\n\\left.\\right.\n\\end{proof}" + "\\begin{proof}\n\\newcommand{\\x}{\\left.\\right.}\n\\left.\\right.\\end{proof}" , Para [ Str "1234567890abcdefghi" ] , Para [ Link diff --git a/test/command/macros.md b/test/command/macros.md index 9f7a0f9d3..7e5f3eca7 100644 --- a/test/command/macros.md +++ b/test/command/macros.md @@ -79,8 +79,7 @@ x &= y\\\end{aligned}\] \newcommand{\my}{\phi} \begin{equation} -\phi+\phi -\end{equation} +\phi+\phi\end{equation} ``` ``` diff --git a/test/command/newif.md b/test/command/newif.md index f444f14c9..a68357955 100644 --- a/test/command/newif.md +++ b/test/command/newif.md @@ -43,9 +43,7 @@ should not print should print \fi ^D -should print - -should print +should print should print should print diff --git a/test/latex-reader.native b/test/latex-reader.native index 32ee86899..2da08b5d1 100644 --- a/test/latex-reader.native +++ b/test/latex-reader.native @@ -1312,7 +1312,7 @@ Pandoc ] ] ] - , [ RawBlock (Format "latex") "\\doublespacing" ] + , [ RawBlock (Format "latex") "\\doublespacing\n" ] , [ Para [ Math InlineMath "2+2=4" ] ] , [ Para [ Math InlineMath "x \\in y" ] ] , [ Para [ Math InlineMath "\\alpha \\wedge \\omega" ] ] diff --git a/test/markdown-reader-more.native b/test/markdown-reader-more.native index 7c15f627a..bfd13caed 100644 --- a/test/markdown-reader-more.native +++ b/test/markdown-reader-more.native @@ -67,16 +67,10 @@ Pandoc , Space , Str "environments" ] - , RawBlock (Format "tex") "\\placeformula \\startformula" - , Para - [ Str "L_{1}" - , Space - , Str "=" - , Space - , Str "L_{2}" - , SoftBreak - , RawInline (Format "tex") "\\stopformula" - ] + , RawBlock (Format "tex") "\\placeformula" + , RawBlock + (Format "tex") + "\\startformula\n L_{1} = L_{2}\n \\stopformula" , RawBlock (Format "tex") "\\start[a2]\n\\start[a2]\n\\stop[a2]\n\\stop[a2]" |
