Skip to content

Commit

Permalink
Add LaTeX xspace support (#3797)
Browse files Browse the repository at this point in the history
  • Loading branch information
schrieveslaach authored and jgm committed Jul 13, 2017
1 parent 8b502dd commit 911b63d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Text/Pandoc/Readers/LaTeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,16 @@ mkImage options src = do
return $ imageWith attr (addExtension src defaultExt) "" alt
_ -> return $ imageWith attr src "" alt

doxspace :: PandocMonad m => LP m Inlines
doxspace = do
(space <$ lookAhead (satisfyTok startsWithLetter)) <|> return mempty
where startsWithLetter (Tok _ Word t) =
case T.uncons t of
Just (c, _) | isLetter c -> True
_ -> False
startsWithLetter _ = False


-- converts e.g. \SI{1}[\$]{} to "$ 1" or \SI{1}{\euro} to "1 €"
dosiunitx :: PandocMonad m => LP m Inlines
dosiunitx = do
Expand Down Expand Up @@ -1336,6 +1346,8 @@ inlineCommands = M.fromList $
-- fontawesome
, ("faCheck", lit "\10003")
, ("faClose", lit "\10007")
-- xspace
, ("xspace", doxspace)
]

ttfamily :: PandocMonad m => LP m Inlines
Expand Down
27 changes: 27 additions & 0 deletions test/command/3681.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
```
% pandoc -f latex -t native
\newcommand{\cicd}{CI/CD\xspace}
Software developers create \cicd pipelines to… Following issue can be resolved by \cicd:
^D
[Para [Str "Software",Space,Str "developers",Space,Str "create",Space,Str "CI/CD",Space,Str "pipelines",Space,Str "to\8230",Space,Str "Following",Space,Str "issue",Space,Str "can",Space,Str "be",Space,Str "resolved",Space,Str "by",Space,Str "CI/CD:"]]
```

```
% pandoc -f latex -t native
\newcommand{\cicd}{CI/CD\xspace}
\cicd\footnote{\url{https://en.wikipedia.org/wiki/CI/CD}} is awesome.
^D
[Para [Str "CI/CD",Note [Para [Link ("",[],[]) [Str "https://en.wikipedia.org/wiki/CI/CD"] ("https://en.wikipedia.org/wiki/CI/CD","")]],Space,Str "is",Space,Str "awesome."]]
```

```
% pandoc -f latex -t native
\newcommand{\cicd}{CI/CD\xspace}
\newcommand{\pipeline}{pipeline\xspace}
\cicd\pipeline.
^D
[Para [Str "CI/CD",Space,Str "pipeline."]]
```

0 comments on commit 911b63d

Please sign in to comment.