From 98e1debeb67745a36e6e2c43cc4b44a98aec35a0 Mon Sep 17 00:00:00 2001
From: matze-dd <45763831+matze-dd@users.noreply.github.com>
Date: Tue, 27 Oct 2020 11:33:02 +0100
Subject: [PATCH 1/4] Closes #85
---
yalafi/mathparser.py | 11 ++++++++++-
yalafi/parameters.py | 4 ++++
yalafi/tex2txt.py | 6 ++++++
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/yalafi/mathparser.py b/yalafi/mathparser.py
index fe8ecbce..3b3b711a 100644
--- a/yalafi/mathparser.py
+++ b/yalafi/mathparser.py
@@ -61,7 +61,7 @@ def __init__(self, parser):
def expand_display_math(self, buf, tok, env):
buf.next()
- start = tok.pos
+ start_simple = start = tok.pos
first_section = True
next_repl = True
out = [defs.ActionToken(start),
@@ -93,6 +93,15 @@ def expand_display_math(self, buf, tok, env):
else:
out = [defs.ActionToken(out[-1].pos)]
else:
+ if self.parser.parms.math_displayed_simple:
+ txt = self.parser.get_text_direct(out).strip()
+ out = [defs.ActionToken(start_simple),
+ defs.SpaceToken(start_simple, ' ', pos_fix=True),
+ defs.TextToken(start_simple,
+ self.parser.parms.math_repl_display[0], pos_fix=True)]
+ if txt and txt[-1] in self.parser.parms.math_punctuation:
+ out.append(defs.TextToken(out[-1].pos, txt[-1],
+ pos_fix=True))
out.append(defs.ActionToken(out[-1].pos))
return out
diff --git a/yalafi/parameters.py b/yalafi/parameters.py
index 00c63413..74a63a07 100644
--- a/yalafi/parameters.py
+++ b/yalafi/parameters.py
@@ -329,6 +329,10 @@ def init_collections(self):
#
def init_math_collections(self):
+ # simple replacement for displayed equations?
+ #
+ self.math_displayed_simple = False
+
# things to be ignored in math mode
# - some entries are redundant, if macros are known from text mode
# and expand to 'nothing'
diff --git a/yalafi/tex2txt.py b/yalafi/tex2txt.py
index ee751676..be161906 100644
--- a/yalafi/tex2txt.py
+++ b/yalafi/tex2txt.py
@@ -44,6 +44,8 @@ def read(file):
extr = ['\\' + s for s in opts.extr.split(',')]
else:
extr = []
+ if opts.seqs:
+ parms.math_displayed_simple = True
p = parser.Parser(parms, packages, read_macros=read)
toks = p.parse(latex, extract=extr)
txt, pos = utils.get_txt_pos(toks)
@@ -199,6 +201,7 @@ def __init__(self,
pack=None, # import modules for \usepackage
extr=None, # or string: comma-separated macro list
lang=None, # or set to language code
+ seqs=False, # True: simple replacements for displayed equations
unkn=False): # True: print unknowns
self.ienc = ienc
self.repl = repl
@@ -211,6 +214,7 @@ def __init__(self,
self.pack = pack
self.extr = extr
self.lang = lang
+ self.seqs = seqs
self.unkn = unkn
# function to be called for stand-alone script
@@ -227,6 +231,7 @@ def main():
parser.add_argument('--extr')
parser.add_argument('--lang')
parser.add_argument('--ienc')
+ parser.add_argument('--seqs', action='store_true')
parser.add_argument('--unkn', action='store_true')
cmdline = parser.parse_args()
@@ -242,6 +247,7 @@ def main():
pack=cmdline.pack,
extr=cmdline.extr,
lang=cmdline.lang,
+ seqs=cmdline.seqs,
unkn=cmdline.unkn)
if cmdline.file:
From b1ec4141e841b60adbd049460f130f149930a5f4 Mon Sep 17 00:00:00 2001
From: matze-dd <45763831+matze-dd@users.noreply.github.com>
Date: Tue, 27 Oct 2020 11:35:27 +0100
Subject: [PATCH 2/4] Added test for issue #85
---
tests/test_display.py | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/tests/test_display.py b/tests/test_display.py
index 8103282f..6acb651c 100644
--- a/tests/test_display.py
+++ b/tests/test_display.py
@@ -186,3 +186,22 @@ def test_9():
plain, pos = utils.get_txt_pos(toks)
assert plain_9 == plain
+# simplified equation parsing
+#
+latex_10 = r"""
+\usepackage{amsmath}
+\begin{align}
+ a &= b.
+\end{align}
+"""
+plain_10 = r"""
+ W-W-W.
+"""
+def test_10():
+ parms = parameters.Parameters()
+ parms.math_displayed_simple = True
+ p = parser.Parser(parms)
+ toks = p.parse(latex_10)
+ plain, pos = utils.get_txt_pos(toks)
+ assert plain_10 == plain
+
From e3db803cbec12706e0fed0fe24117631d85bcffd Mon Sep 17 00:00:00 2001
From: matze-dd <45763831+matze-dd@users.noreply.github.com>
Date: Tue, 27 Oct 2020 11:37:40 +0100
Subject: [PATCH 3/4] Closes #85
---
yalafi/shell/proofreader.py | 1 +
yalafi/shell/shell.py | 1 +
2 files changed, 2 insertions(+)
diff --git a/yalafi/shell/proofreader.py b/yalafi/shell/proofreader.py
index 5b6992f6..9c8187eb 100644
--- a/yalafi/shell/proofreader.py
+++ b/yalafi/shell/proofreader.py
@@ -62,6 +62,7 @@ def run_proofreader_options(tex, language, disable, enable,
t2t_options = tex2txt.Options(char=True, repl=cmdline.replace,
defs=cmdline.define, lang=language[:2],
extr=cmdline.extract, unkn=cmdline.list_unknown,
+ seqs=cmdline.simple_equations,
dcls=cmdline.documentclass, pack=cmdline.packages)
if cmdline.plain_input:
diff --git a/yalafi/shell/shell.py b/yalafi/shell/shell.py
index 6f390256..5fedef9d 100644
--- a/yalafi/shell/shell.py
+++ b/yalafi/shell/shell.py
@@ -138,6 +138,7 @@
parser.add_argument('--skip')
parser.add_argument('--plain-input', action='store_true')
parser.add_argument('--list-unknown', action='store_true')
+parser.add_argument('--simple-equations', action='store_true')
parser.add_argument('--language', default=default_option_language)
parser.add_argument('--encoding', default=default_option_encoding)
parser.add_argument('--replace')
From 5376d57d20709e1103d6be62b607708152bb3e45 Mon Sep 17 00:00:00 2001
From: matze-dd <45763831+matze-dd@users.noreply.github.com>
Date: Tue, 27 Oct 2020 11:38:48 +0100
Subject: [PATCH 4/4] Closed issue #85
---
HISTORY.md | 7 ++++++-
README.md | 14 +++++++++++++-
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/HISTORY.md b/HISTORY.md
index 43c1cb30..99332f56 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -3,11 +3,16 @@ Work in progress
- LaTeX macros / environments
- builtins: added \\bibitem, \\bibliographystyle, \\begin{thebibliography}
(issue [#80](../../issues/80))
+- yalafi.shell
+ - added option --simple-equations for simple replacements of displayed
+ equations (issue [#85](../../issues/85))
- yalafi core
- added 'ru' for option --lang (issue [#84](../../issues/84))
+ - added option --seqs for simple replacements of displayed equations
+ (issue [#85](../../issues/85))
- fixed problem in tests/test_packages/test\_latex\_builtins.py
(issue [#86](../../issues/86))
-- README.md: minor edits
+- README.md: updated
Version 1.1.6 (2020/10/19)
--------------------------
diff --git a/README.md b/README.md
index 7be9b397..1a8da1f7 100644
--- a/README.md
+++ b/README.md
@@ -251,6 +251,10 @@ Default option values are set at the Python script beginning.
comma-separated list.
This is useful for check of foreign-language text, if marked accordingly.
Internally used for detection of file inclusions on --include.
+- `--simple-equations`
+ Replace a displayed equation only with a single placeholder from collection
+ 'Paramaters.math\_repl\_display' in file yalafi/parameters; append trailing
+ interpunction, if present.
- `--disable rules`
Comma-separated list of ignored LT rules, is passed as --disable to LT
(default: 'WHITESPACE\_RULE').
@@ -1071,6 +1075,10 @@ are placed at the right side of the alignment character '\&'.
LaTeX does not enforce that, but it is the style found in examples of the
documentation for package amsmath.
+**Remark.**
+For a simplification, see option --simple-equations in section
+[Example application](#example-application).
+
With the default entry
```
EquEnv(self, 'align'),
@@ -1219,7 +1227,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]
- [--unkn] [latexfile]
+ [--seqs] [--unkn] [latexfile]
```
Without positional argument `latexfile`, standard input is read.
@@ -1243,6 +1251,9 @@ Without positional argument `latexfile`, standard input is read.
proof titles, and for handling of macros like '\"\='.
- `--ienc enc`
As option --encoding in section [Example application](#example-application).
+- `--seqs`
+ As option --simple-equations in section
+ [Example application](#example-application).
- `--unkn`
As option --list-unknown in section
[Example application](#example-application).
@@ -1265,6 +1276,7 @@ Invocation of `python -m yalafi ...` differs as follows from
see [the example below](#equation-html-report).
- Added options --dcls and --pack allow modification of predefined LaTeX
macros and environments at Python level.
+- Added option --seqs.
- 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.