Skip to content

Commit

Permalink
Merge pull request #112 from matze-dd/Issue-110
Browse files Browse the repository at this point in the history
Closes #110
  • Loading branch information
matze-dd authored Nov 12, 2020
2 parents 2c18efe + e5ec779 commit 2fd519a
Show file tree
Hide file tree
Showing 28 changed files with 110 additions and 81 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Work in progress
----------------
- **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 packet options.
See for instance file yalafi/packages/amsmath.py.
- yalafi.shell
- added support for multi-language documents (issue [#98](../../issues/98))
- new options --multi-language, --ml-continue-threshold, --ml-rule-threshold,
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -929,11 +929,10 @@ submodules that are activated by the LaTeX filter when executing
This is similar to the previous case.

Each extension module has to provide a list 'require\_packages' of strings
that causes loading of other modules, and a function 'modify\_parameters()'.
It is called by the parser and can modify the passed object of
class 'Parameters'.
that causes loading of other modules, and a function 'init\_module()'.
It is called by the parser and can modify the object of class 'Parameters'.
In order to add macros and environments, it has to construct strings or
object lists that are included in the returned object of class 'ModParm'.
object lists that are included in the returned object of class 'InitModule'.
Classes for definition of macros and environments are described in the
sections starting at [Definition of macros](#definition-of-macros).
For an example, see file
Expand Down
7 changes: 4 additions & 3 deletions tests/defs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

from yalafi.defs import ModParm, Environ, EquEnv
from yalafi.defs import InitModule, Environ, EquEnv

require_packages = ['amsmath'] # for test_modules.py

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

environments = [

Expand All @@ -12,5 +13,5 @@ def modify_parameters(parms):

]

return ModParm(environments=environments)
return InitModule(environments=environments)

2 changes: 1 addition & 1 deletion yalafi/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from . import utils

class ModParm:
class InitModule:
def __init__(self, macros_latex='', macros_python=[], environments=[]):
self.macros_latex = macros_latex
self.macros_python = macros_python
Expand Down
7 changes: 4 additions & 3 deletions yalafi/documentclasses/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# YaLafi: \documentclass{article}
#

from yalafi.defs import ModParm
from yalafi.defs import InitModule

require_packages = []

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

return ModParm()
return InitModule()

7 changes: 4 additions & 3 deletions yalafi/documentclasses/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# YaLafi: \documentclass{book}
#

from yalafi.defs import ModParm
from yalafi.defs import InitModule

require_packages = []

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

return ModParm()
return InitModule()

7 changes: 4 additions & 3 deletions yalafi/documentclasses/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# YaLafi: \documentclass{report}
#

from yalafi.defs import ModParm
from yalafi.defs import InitModule

require_packages = []

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

return ModParm()
return InitModule()

7 changes: 4 additions & 3 deletions yalafi/documentclasses/scrartcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# YaLafi: \documentclass{scrartcl}
#

from yalafi.defs import ModParm
from yalafi.defs import InitModule

require_packages = []

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

macros_latex = r"""
Expand All @@ -16,5 +17,5 @@ def modify_parameters(parms):
"""

return ModParm(macros_latex=macros_latex)
return InitModule(macros_latex=macros_latex)

7 changes: 4 additions & 3 deletions yalafi/documentclasses/scrbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# YaLafi: \documentclass{scrbook}
#

from yalafi.defs import ModParm
from yalafi.defs import InitModule

require_packages = []

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

macros_latex = r"""
Expand All @@ -16,5 +17,5 @@ def modify_parameters(parms):
"""

return ModParm(macros_latex=macros_latex)
return InitModule(macros_latex=macros_latex)

7 changes: 4 additions & 3 deletions yalafi/documentclasses/scrreprt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# YaLafi: \documentclass{scrreprt}
#

from yalafi.defs import ModParm
from yalafi.defs import InitModule

require_packages = []

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

macros_latex = r"""
Expand All @@ -16,5 +17,5 @@ def modify_parameters(parms):
"""

return ModParm(macros_latex=macros_latex)
return InitModule(macros_latex=macros_latex)

10 changes: 6 additions & 4 deletions yalafi/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ def handler (parser, buf, mac, args, pos):
def h_newtheorem(parser, buf, mac, args, pos):
name = parser.get_text_expanded(args[0])
title = parser.get_text_expanded(args[2])
def f(parms):
def f(parser, options):
parms = parser.parms
envs = [defs.Environ(parms, name, args='O', repl=h_theorem(title))]
return defs.ModParm(environments=envs)
parser.modify_parameters(f)
return defs.InitModule(environments=envs)
parser.modify_parameters(f, [])
return []

# heading macros: append '.', unless last char in parms.heading_punct
Expand Down Expand Up @@ -131,9 +132,10 @@ def h_load_defs(parser, buf, mac, args, pos):
#
def h_load_module(prefix):
def f(parser, buf, mac, args, pos):
options = []
pack = parser.get_text_expanded(args[1])
f = utils.get_module_handler(pack, prefix)
parser.init_package(pack, f)
parser.init_package(pack, f, options)
return []
return f

7 changes: 4 additions & 3 deletions yalafi/packages/amsmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# YaLafi module for LaTeX package amsmath
#

from yalafi.defs import Macro, ModParm, EquEnv
from yalafi.defs import Macro, InitModule, EquEnv

require_packages = []

Expand All @@ -15,7 +15,8 @@
# - The spacing macros and \notag are imporant for correct parsing
# of maths material.
#
def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

parms.math_text_macros.append('\\text')

Expand Down Expand Up @@ -56,6 +57,6 @@ def modify_parameters(parms):

]

return ModParm(macros_latex=macros_latex, macros_python=macros_python,
return InitModule(macros_latex=macros_latex, macros_python=macros_python,
environments=environments)

7 changes: 4 additions & 3 deletions yalafi/packages/amsthm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# YaLafi module for LaTeX package amsthm
#

from yalafi.defs import ModParm, Environ, SpaceToken, TextToken
from yalafi.defs import InitModule, Environ, SpaceToken, TextToken

require_packages = []

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

macros_latex = r"""
Expand All @@ -24,7 +25,7 @@ def modify_parameters(parms):

]

return ModParm(macros_latex=macros_latex, macros_python=macros_python,
return InitModule(macros_latex=macros_latex, macros_python=macros_python,
environments=environments)

def h_proof(parser, buf, mac, args, pos):
Expand Down
9 changes: 6 additions & 3 deletions yalafi/packages/babel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
'english': 'en-GB',
'english-au': 'en-AU',
'english-ca': 'en-CA',
'british': 'en-GB',
'english-gb': 'en-GB',
'english-nz': 'en-NZ',
'american': 'en-US',
'english-us': 'en-US',
# 'en-ZA',
'esperanto': 'eo',
Expand Down Expand Up @@ -52,11 +54,12 @@
'chinese': 'zh-CN',
}

from yalafi.defs import ModParm, Macro, LanguageToken
from yalafi.defs import InitModule, Macro, LanguageToken

require_packages = []

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

macros_latex = ''

Expand All @@ -69,7 +72,7 @@ def modify_parameters(parms):

environments = []

return ModParm(macros_latex=macros_latex, macros_python=macros_python,
return InitModule(macros_latex=macros_latex, macros_python=macros_python,
environments=environments)

def modify_language_map(babel, lt):
Expand Down
7 changes: 4 additions & 3 deletions yalafi/packages/biblatex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
#

from yalafi import defs
from yalafi.defs import Macro, ModParm
from yalafi.defs import Macro, InitModule

require_packages = []

cite_text = '0'

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

macros_latex = ''

Expand All @@ -33,7 +34,7 @@ def modify_parameters(parms):

environments = []

return ModParm(macros_latex=macros_latex, macros_python=macros_python,
return InitModule(macros_latex=macros_latex, macros_python=macros_python,
environments=environments)


Expand Down
7 changes: 4 additions & 3 deletions yalafi/packages/glossaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@

import copy
from yalafi import defs, utils
from yalafi.defs import Macro, ModParm
from yalafi.defs import Macro, InitModule

require_packages = []

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

macros_latex = ''

Expand Down Expand Up @@ -89,7 +90,7 @@ def modify_parameters(parms):

environments = []

return ModParm(macros_latex=macros_latex, macros_python=macros_python,
return InitModule(macros_latex=macros_latex, macros_python=macros_python,
environments=environments)

# return a handler function:
Expand Down
7 changes: 4 additions & 3 deletions yalafi/packages/glossaries_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
# \usepackage[docdef=atom]{glossaries-extra}
#

from yalafi.defs import Macro, ModParm
from yalafi.defs import Macro, InitModule

require_packages = ['glossaries']

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

macros_latex = ''

Expand All @@ -27,6 +28,6 @@ def modify_parameters(parms):

environments = []

return ModParm(macros_latex=macros_latex, macros_python=macros_python,
return InitModule(macros_latex=macros_latex, macros_python=macros_python,
environments=environments)

7 changes: 4 additions & 3 deletions yalafi/packages/graphicx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# YaLafi module for LaTeX package graphicx
#

from yalafi.defs import ModParm
from yalafi.defs import InitModule

require_packages = []

def modify_parameters(parms):
def init_module(parser, options):
parms = parser.parms

macros_latex = r"""
Expand All @@ -19,6 +20,6 @@ def modify_parameters(parms):

environments = []

return ModParm(macros_latex=macros_latex, macros_python=macros_python,
return InitModule(macros_latex=macros_latex, macros_python=macros_python,
environments=environments)

Loading

0 comments on commit 2fd519a

Please sign in to comment.