How to use the pylatexenc.latex2text.SpecialsTextSpec function in pylatexenc

To help you get started, we’ve selected a few pylatexenc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phfaist / bibolamazi / bibolamazi / core / butils.py View on Github external
#     # in names perhaps unescaped, like in "Taylor & Francis"
# )

latex2text_latex_context = latex2text.get_default_latex_context_db()
# in most instances when converting to text, keep ``, '',  --, ---, etc. as they are
latex2text_latex_context.add_context_category(
    'override-nonascii-specials',
    prepend=True,
    macros=[],
    environments=[],
    specials=[
        latex2text.SpecialsTextSpec('~', u" "),
        latex2text.SpecialsTextSpec('``', u"\""),
        latex2text.SpecialsTextSpec("''", u"\""),
        latex2text.SpecialsTextSpec("--", u"--"),
        latex2text.SpecialsTextSpec("---", u"---"),
        latex2text.SpecialsTextSpec("!`", u"!`"),
        latex2text.SpecialsTextSpec("?`", u"?`"),
    ]
)

_l2t = latex2text.LatexNodes2Text(
    strict_latex_spaces=True,
    latex_context=latex2text_latex_context,
)


def latex_to_text(x):

    return _l2t.latex_to_text(x, tolerant_parsing=True)
github phfaist / pylatexenc / pylatexenc / latex2text / _defaultspecs.py View on Github external
specs = [
    #
    # CATEGORY: latex-base
    #
    ('latex-base', latex_base_specs),

    #
    # CATEGORY: nonascii-specials
    #
    ('nonascii-specials', {
        'macros': [],
        'environments': [],
        'specials': [
            SpecialsTextSpec('~', u"\N{NO-BREAK SPACE}"),
            SpecialsTextSpec('``', u"\N{LEFT DOUBLE QUOTATION MARK}"),
            SpecialsTextSpec("''", u"\N{RIGHT DOUBLE QUOTATION MARK}"),
            SpecialsTextSpec("--", u"\N{EN DASH}"),
            SpecialsTextSpec("---", u"\N{EM DASH}"),
            SpecialsTextSpec("!`", u"\N{INVERTED EXCLAMATION MARK}"),
            SpecialsTextSpec("?`", u"\N{INVERTED QUESTION MARK}"),
        ]
    }),

    #
    # CATEGORY: latex-ethuebung
    #
    ('latex-ethuebung', {
        'macros': [
            MacroTextSpec('exercise', simplify_repl=_format_uebung),
            MacroTextSpec('uebung', simplify_repl=_format_uebung),
            MacroTextSpec('hint', 'Hint: %s'),
github phfaist / pylatexenc / pylatexenc / latex2text / _defaultspecs.py View on Github external
EnvironmentTextSpec('center', simplify_repl='\n%s\n'),
        EnvironmentTextSpec('flushleft', simplify_repl='\n%s\n'),
        EnvironmentTextSpec('flushright', simplify_repl='\n%s\n'),

        EnvironmentTextSpec('exenumerate', discard=False),
        EnvironmentTextSpec('enumerate', discard=False),
        EnvironmentTextSpec('list', discard=False),
        EnvironmentTextSpec('itemize', discard=False),
        EnvironmentTextSpec('subequations', discard=False),
        EnvironmentTextSpec('figure', discard=False),
        EnvironmentTextSpec('table', discard=False),

    ],
    'specials': [
        SpecialsTextSpec('&', '   '), # ignore tabular alignments, just add a little space
    ],

    'macros': [
        # NOTE: macro will only be assigned arguments if they are explicitly defined as
        #       accepting arguments in latexwalker.py.
        MacroTextSpec('emph', discard=False),
        MacroTextSpec('textrm', discard=False),
        MacroTextSpec('textit', discard=False),
        MacroTextSpec('textbf', discard=False),
        MacroTextSpec('textsc', discard=False),
        MacroTextSpec('textsl', discard=False),
        MacroTextSpec('text', discard=False),

        MacroTextSpec('mathrm', discard=False),
        MacroTextSpec('mathbb', discard=False),
        MacroTextSpec('mathbf', discard=False),
github phfaist / pylatexenc / pylatexenc / latex2text / _defaultspecs.py View on Github external
#
    # CATEGORY: latex-base
    #
    ('latex-base', latex_base_specs),

    #
    # CATEGORY: nonascii-specials
    #
    ('nonascii-specials', {
        'macros': [],
        'environments': [],
        'specials': [
            SpecialsTextSpec('~', u"\N{NO-BREAK SPACE}"),
            SpecialsTextSpec('``', u"\N{LEFT DOUBLE QUOTATION MARK}"),
            SpecialsTextSpec("''", u"\N{RIGHT DOUBLE QUOTATION MARK}"),
            SpecialsTextSpec("--", u"\N{EN DASH}"),
            SpecialsTextSpec("---", u"\N{EM DASH}"),
            SpecialsTextSpec("!`", u"\N{INVERTED EXCLAMATION MARK}"),
            SpecialsTextSpec("?`", u"\N{INVERTED QUESTION MARK}"),
        ]
    }),

    #
    # CATEGORY: latex-ethuebung
    #
    ('latex-ethuebung', {
        'macros': [
            MacroTextSpec('exercise', simplify_repl=_format_uebung),
            MacroTextSpec('uebung', simplify_repl=_format_uebung),
            MacroTextSpec('hint', 'Hint: %s'),
            MacroTextSpec('hints', 'Hints: %s'),
            MacroTextSpec('hinweis', 'Hinweis: %s'),
github phfaist / bibolamazi / bibolamazi / core / butils.py View on Github external
latex2text_latex_context = latex2text.get_default_latex_context_db()
# in most instances when converting to text, keep ``, '',  --, ---, etc. as they are
latex2text_latex_context.add_context_category(
    'override-nonascii-specials',
    prepend=True,
    macros=[],
    environments=[],
    specials=[
        latex2text.SpecialsTextSpec('~', u" "),
        latex2text.SpecialsTextSpec('``', u"\""),
        latex2text.SpecialsTextSpec("''", u"\""),
        latex2text.SpecialsTextSpec("--", u"--"),
        latex2text.SpecialsTextSpec("---", u"---"),
        latex2text.SpecialsTextSpec("!`", u"!`"),
        latex2text.SpecialsTextSpec("?`", u"?`"),
    ]
)

_l2t = latex2text.LatexNodes2Text(
    strict_latex_spaces=True,
    latex_context=latex2text_latex_context,
)


def latex_to_text(x):

    return _l2t.latex_to_text(x, tolerant_parsing=True)
github phfaist / bibolamazi / bibolamazi / core / butils.py View on Github external
#     # do NOT replace tabular alignment symbol '&', because most often it's used
#     # in names perhaps unescaped, like in "Taylor & Francis"
# )

latex2text_latex_context = latex2text.get_default_latex_context_db()
# in most instances when converting to text, keep ``, '',  --, ---, etc. as they are
latex2text_latex_context.add_context_category(
    'override-nonascii-specials',
    prepend=True,
    macros=[],
    environments=[],
    specials=[
        latex2text.SpecialsTextSpec('~', u" "),
        latex2text.SpecialsTextSpec('``', u"\""),
        latex2text.SpecialsTextSpec("''", u"\""),
        latex2text.SpecialsTextSpec("--", u"--"),
        latex2text.SpecialsTextSpec("---", u"---"),
        latex2text.SpecialsTextSpec("!`", u"!`"),
        latex2text.SpecialsTextSpec("?`", u"?`"),
    ]
)

_l2t = latex2text.LatexNodes2Text(
    strict_latex_spaces=True,
    latex_context=latex2text_latex_context,
)


def latex_to_text(x):

    return _l2t.latex_to_text(x, tolerant_parsing=True)
github phfaist / pylatexenc / pylatexenc / latex2text / _defaultspecs.py View on Github external
('latex-base', latex_base_specs),

    #
    # CATEGORY: nonascii-specials
    #
    ('nonascii-specials', {
        'macros': [],
        'environments': [],
        'specials': [
            SpecialsTextSpec('~', u"\N{NO-BREAK SPACE}"),
            SpecialsTextSpec('``', u"\N{LEFT DOUBLE QUOTATION MARK}"),
            SpecialsTextSpec("''", u"\N{RIGHT DOUBLE QUOTATION MARK}"),
            SpecialsTextSpec("--", u"\N{EN DASH}"),
            SpecialsTextSpec("---", u"\N{EM DASH}"),
            SpecialsTextSpec("!`", u"\N{INVERTED EXCLAMATION MARK}"),
            SpecialsTextSpec("?`", u"\N{INVERTED QUESTION MARK}"),
        ]
    }),

    #
    # CATEGORY: latex-ethuebung
    #
    ('latex-ethuebung', {
        'macros': [
            MacroTextSpec('exercise', simplify_repl=_format_uebung),
            MacroTextSpec('uebung', simplify_repl=_format_uebung),
            MacroTextSpec('hint', 'Hint: %s'),
            MacroTextSpec('hints', 'Hints: %s'),
            MacroTextSpec('hinweis', 'Hinweis: %s'),
            MacroTextSpec('hinweise', 'Hinweise: %s'),
        ],
        'environments': [],
github phfaist / pylatexenc / pylatexenc / latex2text / _defaultspecs.py View on Github external
#
    ('latex-base', latex_base_specs),

    #
    # CATEGORY: nonascii-specials
    #
    ('nonascii-specials', {
        'macros': [],
        'environments': [],
        'specials': [
            SpecialsTextSpec('~', u"\N{NO-BREAK SPACE}"),
            SpecialsTextSpec('``', u"\N{LEFT DOUBLE QUOTATION MARK}"),
            SpecialsTextSpec("''", u"\N{RIGHT DOUBLE QUOTATION MARK}"),
            SpecialsTextSpec("--", u"\N{EN DASH}"),
            SpecialsTextSpec("---", u"\N{EM DASH}"),
            SpecialsTextSpec("!`", u"\N{INVERTED EXCLAMATION MARK}"),
            SpecialsTextSpec("?`", u"\N{INVERTED QUESTION MARK}"),
        ]
    }),

    #
    # CATEGORY: latex-ethuebung
    #
    ('latex-ethuebung', {
        'macros': [
            MacroTextSpec('exercise', simplify_repl=_format_uebung),
            MacroTextSpec('uebung', simplify_repl=_format_uebung),
            MacroTextSpec('hint', 'Hint: %s'),
            MacroTextSpec('hints', 'Hints: %s'),
            MacroTextSpec('hinweis', 'Hinweis: %s'),
            MacroTextSpec('hinweise', 'Hinweise: %s'),
        ],
github phfaist / pylatexenc / pylatexenc / latex2text / _defaultspecs.py View on Github external
# CATEGORY: latex-base
    #
    ('latex-base', latex_base_specs),

    #
    # CATEGORY: nonascii-specials
    #
    ('nonascii-specials', {
        'macros': [],
        'environments': [],
        'specials': [
            SpecialsTextSpec('~', u"\N{NO-BREAK SPACE}"),
            SpecialsTextSpec('``', u"\N{LEFT DOUBLE QUOTATION MARK}"),
            SpecialsTextSpec("''", u"\N{RIGHT DOUBLE QUOTATION MARK}"),
            SpecialsTextSpec("--", u"\N{EN DASH}"),
            SpecialsTextSpec("---", u"\N{EM DASH}"),
            SpecialsTextSpec("!`", u"\N{INVERTED EXCLAMATION MARK}"),
            SpecialsTextSpec("?`", u"\N{INVERTED QUESTION MARK}"),
        ]
    }),

    #
    # CATEGORY: latex-ethuebung
    #
    ('latex-ethuebung', {
        'macros': [
            MacroTextSpec('exercise', simplify_repl=_format_uebung),
            MacroTextSpec('uebung', simplify_repl=_format_uebung),
            MacroTextSpec('hint', 'Hint: %s'),
            MacroTextSpec('hints', 'Hints: %s'),
            MacroTextSpec('hinweis', 'Hinweis: %s'),
            MacroTextSpec('hinweise', 'Hinweise: %s'),