Skip to content

Commit

Permalink
Closes #147, closes #149
Browse files Browse the repository at this point in the history
  • Loading branch information
matze-dd committed Dec 8, 2020
1 parent 17592d4 commit 0e65981
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Work in progress
(PR [#133](../../pull/133))
- new package xspace: macro \\xspace; **thanks to @blipp**
(PR [#134](../../pull/134), issue [#140](../../issues/140))
- package babel: fixed a problem with parsing of package options
(issue [#147](../../issues/147))
- yalafi.shell
- added option --no-specials (issue [#131](../../issues/131))
- fixed problem with --add-modules (issue [#144](../../issues/144))
Expand Down
22 changes: 22 additions & 0 deletions tests/test_multi_lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,25 @@ def test_13():
plain = get_ml_txt(latex_13, lang='en-GB')
assert plain == plain_13

# issues 147, 149
#
latex_14 = r"""
"a
\usepackage[english,ngerman,math=normal]{babel}
"a
"""
plain_14 = {
'de-DE': [
"""ä
"""
],
'en-GB': [
"""
"a
"""
]
}
def test_14():
plain = get_ml_txt(latex_14, lang='en-GB')
assert plain == plain_14

18 changes: 13 additions & 5 deletions yalafi/packages/babel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# 'ca-ES-valencia'
'danish': 'da-DK',
'german': 'de-DE',
'ngerman': 'de-DE',
'german-at': 'de-AT',
'german-ch': 'de-CH',
'greek': 'el-GR',
Expand Down Expand Up @@ -87,11 +88,7 @@ def init_module(parser, options):

]

inject_tokens = []
if options:
# set current language to the last in option list
inject_tokens = [LanguageToken(0, lang=translate_lang(options[-1][0]),
hard=True, brk=True)]
inject_tokens = get_language_token(options)

return InitModule(macros_latex=macros_latex, macros_python=macros_python,
environments=environments, inject_tokens=inject_tokens)
Expand Down Expand Up @@ -124,3 +121,14 @@ def h_end_otherlang(parser, buf, mac, args, delim, pos):
def h_end_otherlang_star(parser, buf, mac, args, delim, pos):
return [LanguageToken(pos, back=True)]

# return a list
# - with LanguageToken corresponding to given option
# - or empty, if no language option found
#
def get_language_token(options):
for opt in reversed(options):
if opt[1] is None and opt[0] in language_map:
return [LanguageToken(0, lang=translate_lang(opt[0]),
hard=True, brk=True)]
return []

0 comments on commit 0e65981

Please sign in to comment.