Skip to content

Commit

Permalink
Closes #131
Browse files Browse the repository at this point in the history
  • Loading branch information
matze-dd committed Dec 6, 2020
1 parent 8e581ce commit c92bad7
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 6 deletions.
6 changes: 4 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`<br>
Revert changes from special macros and magic comments described in section
[Modification of LaTeX text](#Modification-of-latex-text).
- `--disable rules`<br>
Comma-separated list of ignored LT rules, is passed as --disable to LT
(default: 'WHITESPACE\_RULE').
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -1414,6 +1422,9 @@ Without positional argument `latexfile`, standard input is read.
- `--unkn`<br>
As option --list-unknown in section
[Example application](#example-application).
- `--nosp`<br>
As option --no-specials in section
[Example application](#example-application).
- `--mula base`<br>
Turn on multi-language processing.
The different text parts are stored in files `<base>.<part>.<language>`.
Expand All @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions tests/test_shell_cmd/test_lt_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

24 changes: 24 additions & 0 deletions tests/test_special.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

11 changes: 11 additions & 0 deletions yalafi/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion yalafi/shell/proofreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))]}
Expand Down
4 changes: 3 additions & 1 deletion yalafi/shell/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:])
Expand Down Expand Up @@ -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?
Expand Down
8 changes: 7 additions & 1 deletion yalafi/tex2txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()

Expand All @@ -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)
Expand Down

0 comments on commit c92bad7

Please sign in to comment.