Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# # 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)
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'),
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),
#
# 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'),
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)
# # 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)
('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': [],
#
('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'),
],
# 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'),