innoconv_mintmod.utils

Utility module

innoconv_mintmod.utils.block_wrap(elem, orig_elem)[source]

Wraps an element in a block if necessary.

If the original element was block panflute expects the return value to be also block. In many places we need to detect this and wrap an inline.

Parameters:
Return type:

panflute.base.Element

Returns:

elem or elem wrapped in panflute.elements.Plain

innoconv_mintmod.utils.destringify(string)[source]

Takes a string and transforms it into list of Str and Space objects.

This function breaks down strings with whitespace. It could be done by calling parse_fragment() but doesn’t have the overhead involed.

Example:
>>> destringify('foo  bar       baz')
[Str(foo), Space, Str(bar), Space, Str(baz)]
Parameters:

string (str) – String to transform

Return type:

list

Returns:

list of panflute.Str and panflute.Space

innoconv_mintmod.utils.extract_identifier(content)[source]

Extract identifier from content and remove annotation element.

\MLabel commands that occur within environments are parsed in a child process (innoconv_mintmod.mintmod_filter.commands.handle_mlabel()). The id attribute can’t be set directly as they can’t access the whole doc tree. As a workaround they create a fake element and add the identifier. This function extracts the identifier and removes the annotation element.

Parameters:content (list) – List of elements
Return type:(list, str)
Returns:updated content list and identifier (might be None)
innoconv_mintmod.utils.get_panzer_bin()[source]

Get path of panzer binary.

innoconv_mintmod.utils.get_remembered_element(doc)[source]

Retrieve rememembered element from the document and forget it.

To remember elements use remember_element().

Parameters:doc (panflute.elements.Doc) – Document where the element is stored
Return type:panflute.base.Element
Returns:The remembered element or None
innoconv_mintmod.utils.log(msg_string, level='INFO')[source]

Log messages when running as a panzer filter.

Parameters:
  • msg_string (str) – Message that is logged
  • level (str) – Log level (INFO, WARNING, ERROR OR CRITICAL)
innoconv_mintmod.utils.parse_cmd(text)[source]

Parse a LaTeX command using regular expressions.

Parses a command like: \foo{bar}{baz}

Parameters:text (str) – String to parse
Return type:(str, list)
Returns:command name and list of command arguments
innoconv_mintmod.utils.parse_fragment(parse_string, as_doc=False, from_format='latex+raw_tex')[source]

Parse a source fragment using panzer.

Parameters:
Return type:

list of panflute.base.Element or panflute.elements.Doc

Returns:

parsed elements

Raises:
  • OSError – if panzer executable is not found
  • RuntimeError – if panzer recursion depth is exceeded
  • RuntimeError – if panzer output could not be parsed
innoconv_mintmod.utils.parse_nested_args(to_parse)[source]

Parse LaTeX command arguments that can have nested commands. Returns arguments and rest string.

Parses strings like: {bar}{baz{}}rest into [['bar', 'baz{}'], 'rest'].

Parameters:to_parse (str) – String to parse
Return type:(list, str)
Returns:parsed arguments and rest string
innoconv_mintmod.utils.remember_element(doc, elem)[source]

Rememember an element in the document for later.

To retrieve remembered elements use get_remembered_element().

Parameters:
innoconv_mintmod.utils.remove_empty_paragraphs(doc)[source]

Remove empty paragraphs from document.

Parameters:doc (panflute.elements.Doc) – Document
innoconv_mintmod.utils.to_inline(elem, classes=[], attributes={})[source]

Convert any given pandoc element to inline element(s). Some information may be lost.