latex_to_myst package

Submodules

latex_to_myst.cli module

latex_to_myst.cli.main()[source]

Main CLI Entry Point to Latex-to-Myst

This entry point is invoked in the command line as a console script and can be invoked like:

$ latex2myst my_latex_file.tex my_new_markdown.md

You can see the complete set of options by typing:

$ latex2myst -h

latex_to_myst.directive module

Collection of Helpers to create directive blocks consistent with MyST syntax

The syntax for MyST Directive Blocks that is followed in this repository takes the form of:

```{directivename} arg1 arg2
:key1: metadata1
:key2: metadata2
My directive content.
```
latex_to_myst.directive.create_directive_block(elem, doc, content, block_type, create_using=<class 'panflute.elements.Span'>, label='')[source]

Create a directive block as literal

Parameters
  • elem (panflute.base.Element) –

  • doc (panflute.elements.Doc) –

  • content (Iterable[panflute.base.Element]) –

  • block_type (str) –

  • create_using (Union[panflute.elements.Para, panflute.elements.Span]) –

  • label (str) –

Return type

Union[panflute.elements.Para, panflute.elements.Span]

latex_to_myst.directive.directive_level(elem, doc, starting_level=0)[source]

Check the nested level of a directive block

Parameters
  • elem (panflute.base.Element) –

  • doc (panflute.elements.Doc) –

  • starting_level (int) –

Return type

int

latex_to_myst.directive.elem_has_multiple_figures(elem)[source]

Check if an element is a subplot (subfigures)

Parameters

elem (panflute.base.Element) –

latex_to_myst.directive.image_in_subplot(elem)[source]

Check if an image node is in subplot

Parameters

elem (panflute.elements.Image) –

latex_to_myst.directive.is_directive_block(elem)[source]

Check if an given element is a directive block

Parameters

elem (panflute.base.Element) –

Return type

bool

latex_to_myst.figures module

Figures directives

latex_to_myst.figures.break_long_string(string, max_len=70, indent=0)[source]

Break long string into shorter strings of max_len (with indent added)

Parameters
  • string (str) –

  • max_len (int) –

  • indent (int) –

Return type

str

latex_to_myst.figures.create_image(elem, doc=None)[source]

Create Image Directive Block

Parameters
  • elem (panflute.elements.Image) –

  • doc (Optional[panflute.elements.Doc]) –

Return type

panflute.elements.Span

latex_to_myst.figures.create_subplots(elem, doc=None)[source]

Create Subplot using list-table and return table and substitutions to put in header

Parameters
  • elem (Union[panflute.elements.Para, panflute.table_elements.Table]) –

  • doc (Optional[panflute.elements.Doc]) –

Return type

Tuple[panflute.elements.Para, Iterable[Any]]

latex_to_myst.latex_math module

Handle LaTeX math blocks

Deals with amsthm blocks and also DisplayMath blocks and render them in formats that are compatible with MyST syntax.

latex_to_myst.latex_math.create_amsthm_blocks(elem, doc=None)[source]

Create directive blocks that render AMSTHM

Takes advantage of sphinx-proof sphinx extension to render amsthm blocks. It does the following:

  1. Walk the element to see if a label{} node is found and save that label. Remove that label element if found.

  2. Parses the :py:func`panflute.Div`’s stringified representation to see if pattern like Theorem 1.1 (Theorem Name) or Example 1.1 is encountered. Save the theorem name Theorem Name if found.

  3. Render output as a panflute.Div() element with the sphinx-proof syntax.

The output looks something like:

```{prf:remark} My Remark
:label: remark-1

This is my remark.
```
Parameters
  • elem (panflute.elements.Div) –

  • doc (Optional[panflute.elements.Doc]) –

Return type

panflute.elements.Para

latex_to_myst.latex_math.create_displaymath(elem, doc=None)[source]

Create DisplayMath block

Create a panflute.Span() block that contains the display math using MyST syntax that looks like:

```{math}
:label: my-equation

a = \int_1^2 u(t) dt
```
Parameters
  • elem (panflute.elements.Math) –

  • doc (Optional[panflute.elements.Doc]) –

Return type

panflute.elements.Span

latex_to_myst.main module

latex_to_myst.main.action(elem, doc=None)[source]
Parameters
  • elem (panflute.base.Element) –

  • doc (Optional[panflute.elements.Doc]) –

Return type

panflute.base.Element

latex_to_myst.main.finalize(doc)[source]
Parameters

doc (panflute.elements.Doc) –

latex_to_myst.main.get_element_type(elem)[source]
Parameters

elem (panflute.base.Element) –

latex_to_myst.main.is_isolated_label(elem, doc=None)[source]

check if element is isolated label

latex_to_myst.main.main(doc=None)[source]
latex_to_myst.main.prepare(doc)[source]
Parameters

doc (panflute.elements.Doc) –

Module contents

Pandoc filter for converting LaTeX to MyST