Skip to content

Commit

Permalink
Closes #115
Browse files Browse the repository at this point in the history
  • Loading branch information
matze-dd committed Nov 14, 2020
1 parent 52d5895 commit f7c7304
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ Work in progress
- new options --multi-language, --ml-continue-threshold, --ml-rule-threshold,
--ml-disable, --ml-disablecategories
- yalafi core
- **Changed interface** to extension modules for packages and document
- **changed interface** to extension modules for packages and document
classes (issue [#110](../../issues/110)).
Entry point is now function init\_module() with two arguments: parser and
list of package options.
See for instance yalafi/packages/amsmath.py and yalafi/packages/babel.py.
- added support for multi-language documents (issue [#98](../../issues/98));
including fixed issues [#104](../../issues/104), [#108](../../issues/108),
[#109](../../issues/109)
- added CLI option '--mula file' for multi-language output
- README.md: updated, added section for multi-language support

Version 1.1.7 (2020/11/04)
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ The LaTeX filter can be integrated in shell scripts, compare the examples in
```
python -m yalafi [--nums file] [--repl file] [--defs file] [--dcls class]
[--pack modules] [--extr macros] [--lang xy] [--ienc enc]
[--seqs] [--unkn] [latexfile]
[--seqs] [--unkn] [--mula file] [latexfile]
```
Without positional argument `latexfile`, standard input is read.

Expand Down Expand Up @@ -1361,7 +1361,11 @@ Without positional argument `latexfile`, standard input is read.
- `--unkn`<br>
As option --list-unknown in section
[Example application](#example-application).

- `--mula file`<br>
Turn on multi-language processing.
The different text parts are stored in files `<file>.<part>.<language>`.
If --nums has been specified, the position maps are written to files with
similar naming scheme.

[Back to contents](#contents)

Expand All @@ -1381,6 +1385,7 @@ Invocation of `python -m yalafi ...` differs as follows from
- Added options --dcls and --pack allow modification of predefined LaTeX
macros and environments at Python level.
- Added option --seqs.
- Added option --mula.
- Option --defs expects a file containing macro definitions as LaTeX code.
- Option --ienc is also effective for file from --defs.
- Option --char (position tracking for single characters) is always activated.
Expand Down
16 changes: 16 additions & 0 deletions yalafi/tex2txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def main():
parser.add_argument('--ienc')
parser.add_argument('--seqs', action='store_true')
parser.add_argument('--unkn', action='store_true')
parser.add_argument('--mula')
cmdline = parser.parse_args()

if not cmdline.ienc:
Expand All @@ -276,6 +277,21 @@ def main():
# reopen stdin in text mode: handling of '\r', proper decoding
txt = open(sys.stdin.fileno(), encoding=cmdline.ienc).read()

if cmdline.mula:
# multi-language: write text sections to files
ml = tex2txt(txt, options, multi_language=True)
for lang in ml:
for nr, txt_pos in enumerate(ml[lang]):
with myopen(cmdline.mula + '.' + str(nr + 1) + '.' + lang,
mode='w', encoding='utf-8') as f:
f.write(txt_pos[0])
if not cmdline.nums:
continue
with myopen(cmdline.nums + '.' + str(nr + 1) + '.' + lang,
mode='w', encoding='utf-8') as f:
write_output(txt_pos, None, f)
sys.exit()

if cmdline.nums:
cmdline.nums = myopen(cmdline.nums, encoding='utf-8', mode='w')

Expand Down

0 comments on commit f7c7304

Please sign in to comment.