Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customization of LaTeX math environment #44

Merged
merged 3 commits into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ To disable a link on a reference, set `nolink=True` in the reference's attribute
@eq:id{nolink=True}


### Custom Environments ###

The default LaTeX environment may be overridden by adding an `env` attribute:

$$ y = mx + b $$ {#eq:id env=multiline}

The `env` attribute must be a valid amsmath environment.
If the attribute value is of the form `foo.bar`, `foo` will be used
as the name of the amsmath environment and `bar` will be used as an extra argument
for the environment (e.g. alignat expects an argument for the number of equation columns).


Customization
-------------

Expand Down Expand Up @@ -203,6 +215,9 @@ Pandoc-eqnos may be customized by setting variables in the [metadata block] or o
set to the same integer value. For LaTeX/PDF, this option
offsets the actual section numbers as required.

* `eqnos-default-env` - Name of the default LaTeX environment
(default: 'equation').

Note that variables beginning with `eqnos-` apply to only pandoc-eqnos, whereas variables beginning with `xnos-` apply to all of the pandoc-fignos/eqnos/tablenos/secnos.

Demonstration: Processing [demo3.md] with pandoc + pandoc-eqnos gives numbered equations and references in [pdf][pdf3], [tex][tex3], [html][html3], [epub][epub3], [docx][docx3] and other formats.
Expand Down
20 changes: 18 additions & 2 deletions pandoc_eqnos.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
secoffset = 0 # Section number offset
eqref = False # Flags that \eqref should be used
warninglevel = 2 # 0 - no warnings; 1 - some warnings; 2 - all warnings
default_env = 'equation'

# Processing state variables
cursec = None # Current section
Expand Down Expand Up @@ -186,8 +187,19 @@ def _add_markup(fmt, eq, value):
if eq['is_unnumbered']: # Unnumbered is also unreferenceable
ret = None
elif fmt in ['latex', 'beamer']:
if 'env' in attrs:
env = attrs['env']
else:
env = default_env

splitted = env.split('.')
env = splitted[0]
arg = ''
if len(splitted) > 1:
arg = '{%s}' % splitted[1]

ret = RawInline('tex',
r'\begin{equation}%s\end{equation}'%value[-1])
r'\begin{%s}%s%s\end{%s}'% (env, arg, value[-1], env))
elif fmt in ('html', 'html4', 'html5', 'epub', 'epub2', 'epub3') and \
LABEL_PATTERN.match(attrs.id):
# Present equation and its number in a span
Expand Down Expand Up @@ -300,7 +312,8 @@ def process(meta):
'eqnos-plus-name', 'eqnos-star-name',
'eqnos-number-by-section', 'xnos-number-by-section',
'xnos-number-offset',
'eqnos-eqref']
'eqnos-eqref',
'eqnos-default-env']

if warninglevel:
for name in meta:
Expand Down Expand Up @@ -366,6 +379,9 @@ def process(meta):
if eqref: # Eqref and cleveref are mutually exclusive
cleveref = False

if 'eqnos-default-env' in meta:
default_env = get_meta(meta, 'eqnos-default-env')

def add_tex(meta):
"""Adds tex to the meta data."""

Expand Down