diff --git a/HISTORY.md b/HISTORY.md index 21ad7a17..6922110e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,14 +5,16 @@ Work in progress (PR [#133](../../pull/133)) - new package xspace: macro \\xspace; **thanks to @blipp** (PR [#134](../../pull/134), issue [#140](../../issues/140)) +- yalafi.shell + - added option --no-specials (issue [#131](../../issues/131)) + - fixed problem with --add-modules (issue [#144](../../issues/144)) - yalafi core - **changed interface** to macro handler functions: added argument 'delim' (issue [#136](../../issues/136)) - added approximation of macro \\def (issue [#125](../../issues/125)) + - added option --nosp (issue [#131](../../issues/131)) - fixed bug: macro could consume a closing \} as argument token (issue [#135](../../issues/135)) -- yalafi.shell - - fixed problem with --add-modules (issue [#144](../../issues/144)) - README.md: updated (issue [#137](../../issues/137)) - CI tests: moved to GitHub Actions diff --git a/README.md b/README.md index 3b7ddbce..8ddcdd51 100644 --- a/README.md +++ b/README.md @@ -260,6 +260,9 @@ Default option values are set at the Python script beginning. Replace a displayed equation only with a single placeholder from collection 'math\_repl\_display' in file yalafi/parameters; append trailing interpunction, if present. +- `--no-specials`
+ Revert changes from special macros and magic comments described in section + [Modification of LaTeX text](#Modification-of-latex-text). - `--disable rules`
Comma-separated list of ignored LT rules, is passed as --disable to LT (default: 'WHITESPACE\_RULE'). @@ -834,6 +837,11 @@ You can do that in the LaTeX code, or after filtering in the plain text. ### Modification of LaTeX text +The following operations can be deactivated with options --nosp and +--no-specials of yalafi and yalafi.shell, respectively. +For instance, macro \\LTadd will be defined, but it will *not* add its +argument to the plain text. + **Special macros.** Small modifications, for instance concerning interpunction, can be made with the predefined macros \\LTadd, \\LTalter and \\LTskip. @@ -1384,7 +1392,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] [--mula base] [latexfile] + [--seqs] [--unkn] [--nosp] [--mula base] [latexfile] ``` Without positional argument `latexfile`, standard input is read. @@ -1414,6 +1422,9 @@ Without positional argument `latexfile`, standard input is read. - `--unkn`
As option --list-unknown in section [Example application](#example-application). +- `--nosp`
+ As option --no-specials in section + [Example application](#example-application). - `--mula base`
Turn on multi-language processing. The different text parts are stored in files `..`. @@ -1438,6 +1449,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 --nosp. - Added option --mula. - Option --defs expects a file containing macro definitions as LaTeX code. - Option --ienc is also effective for file from --defs. diff --git a/tests/test_shell_cmd/test_lt_options.py b/tests/test_shell_cmd/test_lt_options.py index ebb324b1..ab761ec0 100644 --- a/tests/test_shell_cmd/test_lt_options.py +++ b/tests/test_shell_cmd/test_lt_options.py @@ -178,3 +178,25 @@ def test_5(): + test_dir + 'modules.tex', latex_5, 'utf-8') assert lt_in == lt_in_5 +# test --no-specials +# +latex_6 = r""" +\LTadd{A} +\LTskip{B} +\LTalter CD +%%% LT-SKIP-BEGIN +X +%%% LT-SKIP-END +""" +lt_in_6 = """ +--json --encoding utf-8 --language en-GB --disable WHITESPACE_RULE - + +B +C +X + +""" +def test_6(): + lt_in = run_shell.get_lt_in('--no-specials', latex_6, 'utf-8') + assert lt_in == lt_in_6 + diff --git a/tests/test_special.py b/tests/test_special.py index d92baabd..fb2dfed8 100644 --- a/tests/test_special.py +++ b/tests/test_special.py @@ -121,3 +121,27 @@ def test_5(): plain, pos = utils.get_txt_pos(toks) assert plain_5 == plain +# test option --nosp +# +latex_6 = r""" +\LTadd{A} +\LTskip{B} +\LTalter CD +%%% LT-SKIP-BEGIN +X +%%% LT-SKIP-END +""" +plain_6 = """ +B +C +X +""" + +def test_6(): + parms =parameters.Parameters() + parms.no_specials() + p = parser.Parser(parms) + toks = p.parse(latex_6) + plain, pos = utils.get_txt_pos(toks) + assert plain_6 == plain + diff --git a/yalafi/parameters.py b/yalafi/parameters.py index 562227e4..e68a2454 100644 --- a/yalafi/parameters.py +++ b/yalafi/parameters.py @@ -441,6 +441,17 @@ def change_parser_lang(self, tok): def lang_context_lang(self): return self.parser_lang_stack[-1][1] + # deactivate special macros and magic comments + # + def no_specials(self): + self.comment_skip_begin = 'x' + self.comment_skip_end = 'x' + self.macro_defs_python += [ + Macro(self, self.macro_filter_add, args='A', repl=''), + Macro(self, self.macro_filter_alter, args='AA', repl='#1'), + Macro(self, self.macro_filter_skip, args='A', repl='#1'), + ] + def __init__(self, language='en'): self.init_collections() self.init_math_collections() diff --git a/yalafi/shell/proofreader.py b/yalafi/shell/proofreader.py index a8249d8e..5132c0e4 100644 --- a/yalafi/shell/proofreader.py +++ b/yalafi/shell/proofreader.py @@ -63,7 +63,8 @@ def run_proofreader_options(tex, language, disable, enable, defs=cmdline.define, lang=language, extr=cmdline.extract, unkn=cmdline.list_unknown, seqs=cmdline.simple_equations, - dcls=cmdline.documentclass, pack=cmdline.packages) + dcls=cmdline.documentclass, pack=cmdline.packages, + nosp=cmdline.no_specials) if cmdline.plain_input: plain_map = {language: [(tex, list(range(1, len(tex) + 1)))]} diff --git a/yalafi/shell/shell.py b/yalafi/shell/shell.py index 9299709f..dc75aacd 100644 --- a/yalafi/shell/shell.py +++ b/yalafi/shell/shell.py @@ -174,6 +174,7 @@ parser.add_argument('--ml-disablecategories', default=default_option_ml_disablecategories) parser.add_argument('--no-config', action='store_true') +parser.add_argument('--no-specials', action='store_true') parser.add_argument('file', nargs='*') cmdline = parser.parse_args(sys.argv[1:]) @@ -263,7 +264,8 @@ sys.stderr.flush() opts = tex2txt.Options(extr=inclusion_macros, repl=cmdline.replace, defs=cmdline.define, lang=cmdline.language[:2], - dcls=cmdline.documentclass, pack=cmdline.packages) + dcls=cmdline.documentclass, pack=cmdline.packages, + nosp=cmdline.no_specials) def skip_file(fn): # does file name match regex from option --skip? diff --git a/yalafi/tex2txt.py b/yalafi/tex2txt.py index 77092a60..a3ff6c2d 100644 --- a/yalafi/tex2txt.py +++ b/yalafi/tex2txt.py @@ -47,6 +47,8 @@ def read(file): extr = [] if opts.seqs: parms.math_displayed_simple = True + if opts.nosp: + parms.no_specials() if modify_parms: modify_parms(parms) @@ -221,6 +223,7 @@ def __init__(self, extr=None, # or string: comma-separated macro list lang=None, # or set to language code seqs=False, # True: simple replacements for displayed equations + nosp=False, # True: deactivate special macros and comments unkn=False): # True: print unknowns self.ienc = ienc self.repl = repl @@ -234,6 +237,7 @@ def __init__(self, self.extr = extr self.lang = lang self.seqs = seqs + self.nosp = nosp self.unkn = unkn # function to be called for stand-alone script @@ -252,6 +256,7 @@ def main(): parser.add_argument('--ienc') parser.add_argument('--seqs', action='store_true') parser.add_argument('--unkn', action='store_true') + parser.add_argument('--nosp', action='store_true') parser.add_argument('--mula') cmdline = parser.parse_args() @@ -268,7 +273,8 @@ def main(): extr=cmdline.extr, lang=cmdline.lang, seqs=cmdline.seqs, - unkn=cmdline.unkn) + unkn=cmdline.unkn, + nosp=cmdline.nosp) if cmdline.file: f = myopen(cmdline.file, encoding=cmdline.ienc)