diff --git a/README.md b/README.md index f30ff3f..57ab75f 100644 --- a/README.md +++ b/README.md @@ -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 ------------- @@ -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. diff --git a/pandoc_eqnos.py b/pandoc_eqnos.py index 3104e79..87568c3 100644 --- a/pandoc_eqnos.py +++ b/pandoc_eqnos.py @@ -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 @@ -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 @@ -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: @@ -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."""