mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-25 01:36:45 +00:00
LaTeX reader: handle otherlanguage environment...
...and language-name environments like
`\begin{french}...\end{french}`.
Closes #9202.
This commit is contained in:
@@ -61,7 +61,8 @@ import Text.Pandoc.Readers.LaTeX.Table (tableEnvironments)
|
||||
import Text.Pandoc.Readers.LaTeX.Macro (macroDef)
|
||||
import Text.Pandoc.Readers.LaTeX.Lang (inlineLanguageCommands,
|
||||
enquoteCommands,
|
||||
babelLangToBCP47, setDefaultLanguage)
|
||||
babelLangToBCP47,
|
||||
setDefaultLanguage)
|
||||
import Text.Pandoc.Readers.LaTeX.SIunitx (siunitxCommands)
|
||||
import Text.Pandoc.Readers.LaTeX.Inline (acronymCommands, refCommands,
|
||||
nameCommands, charCommands,
|
||||
@@ -1045,8 +1046,24 @@ environments = M.union (tableEnvironments blocks inline) $
|
||||
, ("togglefalse", braced >>= setToggle False)
|
||||
, ("iftoggle", try $ ifToggle >> block)
|
||||
, ("CSLReferences", braced >> braced >> env "CSLReferences" blocks)
|
||||
, ("otherlanguage", env "otherlanguage" otherlanguageEnv)
|
||||
]
|
||||
|
||||
otherlanguageEnv :: PandocMonad m => LP m Blocks
|
||||
otherlanguageEnv = do
|
||||
skipopts
|
||||
babelLang <- untokenize <$> braced
|
||||
case babelLangToBCP47 babelLang of
|
||||
Just lang -> divWith ("", [], [("lang", renderLang lang)]) <$> blocks
|
||||
Nothing -> blocks
|
||||
|
||||
langEnvironment :: PandocMonad m => Text -> LP m Blocks
|
||||
langEnvironment name =
|
||||
case babelLangToBCP47 name of
|
||||
Just lang ->
|
||||
env name (divWith ("", [], [("lang", renderLang lang)]) <$> blocks)
|
||||
Nothing -> mzero -- fall through to raw environment
|
||||
|
||||
filecontents :: PandocMonad m => LP m Blocks
|
||||
filecontents = try $ do
|
||||
controlSeq "begin"
|
||||
@@ -1064,6 +1081,7 @@ environment = try $ do
|
||||
controlSeq "begin"
|
||||
name <- untokenize <$> braced
|
||||
M.findWithDefault mzero name environments <|>
|
||||
langEnvironment name <|>
|
||||
theoremEnvironment blocks opt name <|>
|
||||
if M.member name (inlineEnvironments
|
||||
:: M.Map Text (LP PandocPure Inlines))
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
```
|
||||
% pandoc -f latex -t native
|
||||
\begin{otherlanguage}{french}
|
||||
Bonjour.
|
||||
\end{otherlanguage}
|
||||
^D
|
||||
[ Div
|
||||
( "" , [] , [ ( "lang" , "fr" ) ] )
|
||||
[ Para [ Str "Bonjour." ] ]
|
||||
]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f latex -t native
|
||||
\begin{otherlanguage*}{french}
|
||||
Bonjour.
|
||||
\end{otherlanguage*}
|
||||
^D
|
||||
[ Div
|
||||
( "" , [ "otherlanguage*" ] , [] )
|
||||
[ Para
|
||||
[ Span ( "" , [] , [] ) [ Str "french" ]
|
||||
, SoftBreak
|
||||
, Str "Bonjour."
|
||||
]
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f latex -t native
|
||||
\textfrench{Bonjour}
|
||||
^D
|
||||
[ Para
|
||||
[ Span ( "" , [] , [ ( "lang" , "fr" ) ] ) [ Str "Bonjour" ]
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f latex -t native
|
||||
\foreignlanguage{swissgerman}{Guten tag}
|
||||
^D
|
||||
[ Para
|
||||
[ Span
|
||||
( "" , [] , [ ( "lang" , "de-CH-1901" ) ] )
|
||||
[ Str "Guten" , Space , Str "tag" ]
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f latex -t native
|
||||
\begin{french}
|
||||
Bonjour.
|
||||
\end{french}
|
||||
^D
|
||||
[ Div
|
||||
( "" , [] , [ ( "lang" , "fr" ) ] )
|
||||
[ Para [ Str "Bonjour." ] ]
|
||||
]
|
||||
```
|
||||
Reference in New Issue
Block a user