173 |
174 | {% include "breadcrumbs.html" %}
175 |
176 |
177 |
178 | Shortcuts
179 |
180 |
183 |
184 |
185 | {% if theme_pytorch_project == 'tutorials' %}
186 |
187 |
188 |
{{ pagename }}
189 |
190 |
191 |
 }})
192 |
Run in Google Colab
193 |
Colab
194 |
195 |
196 |
 }})
197 |
Download Notebook
198 |
Notebook
199 |
200 |
201 |
 }})
202 |
View on GitHub
203 |
GitHub
204 |
205 |
206 |
207 | {% endif %}
208 |
209 | {%- block content %}
210 | {% if theme_style_external_links|tobool %}
211 |
212 | {% else %}
213 |
214 | {% endif %}
215 |
216 | {%- block document %}
217 |
218 | {% block body %}{% endblock %}
219 |
220 | {% if self.comments()|trim %}
221 |
222 | {% block comments %}{% endblock %}
223 |
224 | {% endif%}
225 |
226 | {%- endblock %}
227 | {% include "footer.html" %}
228 |
229 | {%- endblock %}
230 |
231 |
232 |
233 |
238 |
239 |
240 |
241 |
242 | {% include "versions.html" %}
243 |
244 | {% if not embedded %}
245 |
246 | {% if sphinx_version >= "1.8.0" %}
247 |
248 | {%- for scriptfile in script_files %}
249 | {{ js_tag(scriptfile) }}
250 | {%- endfor %}
251 | {% else %}
252 |
263 | {%- for scriptfile in script_files %}
264 |
265 | {%- endfor %}
266 | {% endif %}
267 |
268 | {% endif %}
269 |
270 |
271 |
272 |
273 |
274 |
279 |
280 | {% endblock %}
281 |
282 | {%- block footer %} {% endblock %}
283 |
284 |
285 |
286 |
287 |
307 |
308 | {% include "cookie_banner.html" %}
309 |
310 |
311 |
312 |
313 |
314 |
315 |
323 |
324 |
325 |
326 |
327 | {% for link in theme_variables.main_menu_links %}
328 | -
329 | {{ link['name'] }}
330 |
331 | {% endfor %}
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
356 |
357 |
358 |
375 |
376 |
377 |
--------------------------------------------------------------------------------
/docs/source/_templates/theme_variables.jinja:
--------------------------------------------------------------------------------
1 | {%- set urls = {
2 | 'github': 'https://github.com/alvinwan/texsoup',
3 | 'github_issues': 'https://github.com/alvinwan/texsoup/issues',
4 | 'getting_started': 'https://texsoup.alvinwan.com/docs/quickstart.html',
5 | 'docs': 'https://texsoup.alvinwan.com/docs/',
6 | 'home': 'https://texsoup.alvinwan.com/',
7 | 'md2py': 'https://github.com/alvinwan/md2py',
8 | 'tex2py': 'https://github.com/alvinwan/tex2py'
9 | }
10 | -%}
11 | {%- set main_menu_links = [
12 | {'name': 'Home', 'href': urls['home']},
13 | {'name': 'Docs', 'href': urls['docs']},
14 | {'name': 'Github', 'href': urls['github'],}
15 | ]
16 | -%}
17 | {%- set footer_columns = [
18 | {'name': 'TexSoup', 'href': urls['home'], 'links': [
19 | {'name': 'Getting Started', 'href': urls['getting_started']}
20 | ]},
21 | {'name': 'Support', 'links': [
22 | {'name': 'Docs', 'href': urls['docs']},
23 | {'name': 'Github Issues', 'href': urls['github_issues']}
24 | ]},
25 | {'name': 'Related', 'links': [
26 | {'name': 'Markdown2Python', 'href': urls['md2py']},
27 | {'name': 'LaTeX2Python', 'href': urls['tex2py']}
28 | ]}
29 | ]
30 | -%}
31 |
--------------------------------------------------------------------------------
/docs/source/categorizer.rst:
--------------------------------------------------------------------------------
1 | Categorizing Mechanics
2 | ===================================
3 |
4 | .. automodule:: TexSoup.category
5 |
6 | Categorizer
7 | -----------------------------------
8 |
9 | .. autofunction:: categorize
10 |
--------------------------------------------------------------------------------
/docs/source/conf.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # -*- coding: utf-8 -*-
3 | #
4 | # TexSoup documentation build configuration file, created by
5 | # sphinx-quickstart on Fri Dec 23 13:31:47 2016.
6 | #
7 | # This file is execfile()d with the current directory set to its
8 | # containing dir.
9 | #
10 | # Note that not all possible configuration values are present in this
11 | # autogenerated file.
12 | #
13 | # All configuration values have a default; values that are commented out
14 | # serve to show the default.
15 |
16 | # If extensions (or modules to document with autodoc) are in another directory,
17 | # add these directories to sys.path here. If the directory is relative to the
18 | # documentation root, use os.path.abspath to make it absolute, like shown here.
19 | #
20 | import os
21 | # import sys
22 |
23 | # source code directory, relative to this file, for sphinx-autobuild
24 | # sys.path.insert(0, os.path.abspath('../..'))
25 |
26 | import TexSoup
27 |
28 | RELEASE = os.environ.get('RELEASE', False)
29 |
30 | import pytorch_sphinx_theme
31 |
32 | # -- General configuration ------------------------------------------------
33 |
34 | # If your documentation needs a minimal Sphinx version, state it here.
35 | #
36 | needs_sphinx = '1.6'
37 |
38 | # Add any Sphinx extension module names here, as strings. They can be
39 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
40 | # ones.
41 | extensions = [
42 | 'sphinx.ext.autodoc',
43 | 'sphinx.ext.autosummary',
44 | 'sphinx.ext.doctest',
45 | 'sphinx.ext.intersphinx',
46 | 'sphinx.ext.todo',
47 | 'sphinx.ext.coverage',
48 | 'sphinx.ext.napoleon',
49 | 'sphinx.ext.viewcode',
50 | 'sphinxcontrib.katex',
51 | ]
52 |
53 | # katex options
54 | #
55 | #
56 |
57 | katex_options = r'''
58 | delimiters : [
59 | {left: "$$", right: "$$", display: true},
60 | {left: "\\(", right: "\\)", display: false},
61 | {left: "\\[", right: "\\]", display: true}
62 | ]
63 | '''
64 |
65 | napoleon_use_ivar = True
66 |
67 | # Add any paths that contain templates here, relative to this directory.
68 | templates_path = ['_templates']
69 |
70 | # The suffix(es) of source filenames.
71 | # You can specify multiple suffix as a list of string:
72 | #
73 | # source_suffix = ['.rst', '.md']
74 | source_suffix = '.rst'
75 |
76 | # The master toctree document.
77 | master_doc = 'index'
78 |
79 | # General information about the project.
80 | project = 'TexSoup'
81 | copyright = '2020, Alvin Wan'
82 | author = 'Alvin Wan'
83 |
84 | # The version info for the project you're documenting, acts as replacement for
85 | # |version| and |release|, also used in various other places throughout the
86 | # built documents.
87 | #
88 | # The short X.Y version.
89 | # TODO: change to [:2] at v1.0
90 | version = 'master (' + TexSoup.__version__ + ' )'
91 | # The full version, including alpha/beta/rc tags.
92 | # TODO: verify this works as expected
93 | release = 'master'
94 |
95 | # The language for content autogenerated by Sphinx. Refer to documentation
96 | # for a list of supported languages.
97 | #
98 | # This is also used if you do content translation via gettext catalogs.
99 | # Usually you set "language" from the command line for these cases.
100 | language = None
101 |
102 | # List of patterns, relative to source directory, that match files and
103 | # directories to ignore when looking for source files.
104 | # This patterns also effect to html_static_path and html_extra_path
105 | exclude_patterns = []
106 |
107 | # The name of the Pygments (syntax highlighting) style to use.
108 | pygments_style = 'sphinx'
109 |
110 | # If true, `todo` and `todoList` produce output, else they produce nothing.
111 | todo_include_todos = True
112 |
113 | # Disable docstring inheritance
114 | autodoc_inherit_docstrings = False
115 |
116 |
117 | # -- katex javascript in header
118 | #
119 | # def setup(app):
120 | # app.add_javascript("https://cdn.jsdelivr.net/npm/katex@0.10.0-beta/dist/katex.min.js")
121 |
122 |
123 | # -- Options for HTML output ----------------------------------------------
124 | #
125 | # The theme to use for HTML and HTML Help pages. See the documentation for
126 | # a list of builtin themes.
127 | #
128 | #
129 | #
130 |
131 | html_theme = 'pytorch_sphinx_theme'
132 | html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
133 |
134 | # Theme options are theme-specific and customize the look and feel of a theme
135 | # further. For a list of options available for each theme, see the
136 | # documentation.
137 |
138 | html_theme_options = {
139 | 'pytorch_project': 'docs',
140 | 'canonical_url': 'https://texsoup.alvinwan.com',
141 | 'collapse_navigation': False,
142 | 'display_version': True,
143 | 'logo_only': True,
144 | }
145 |
146 | html_logo = '_static/images/logo-dark.svg'
147 |
148 |
149 | # Add any paths that contain custom static files (such as style sheets) here,
150 | # relative to this directory. They are copied after the builtin static files,
151 | # so a file named "default.css" will overwrite the builtin "default.css".
152 | html_static_path = ['_static'] # , '_images']
153 |
154 |
155 | # Called automatically by Sphinx, making this `conf.py` an "extension".
156 | def setup(app):
157 | # NOTE: in Sphinx 1.8+ `html_css_files` is an official configuration value
158 | # and can be moved outside of this function (and the setup(app) function
159 | # can be deleted).
160 | html_css_files = [
161 | 'https://cdn.jsdelivr.net/npm/katex@0.10.0-beta/dist/katex.min.css'
162 | ]
163 |
164 | # In Sphinx 1.8 it was renamed to `add_css_file`, 1.7 and prior it is
165 | # `add_stylesheet` (deprecated in 1.8).
166 | add_css = getattr(app, 'add_css_file', app.add_stylesheet)
167 | for css_file in html_css_files:
168 | add_css(css_file)
169 |
170 |
171 | # -- Options for HTMLHelp output ------------------------------------------
172 |
173 | # Output file base name for HTML help builder.
174 | htmlhelp_basename = 'TexSoupdoc'
175 |
176 |
177 | # -- Options for LaTeX output ---------------------------------------------
178 |
179 | latex_elements = {
180 | # The paper size ('letterpaper' or 'a4paper').
181 | #
182 | # 'papersize': 'letterpaper',
183 |
184 | # The font size ('10pt', '11pt' or '12pt').
185 | #
186 | # 'pointsize': '10pt',
187 |
188 | # Additional stuff for the LaTeX preamble.
189 | #
190 | # 'preamble': '',
191 |
192 | # Latex figure (float) alignment
193 | #
194 | # 'figure_align': 'htbp',
195 | }
196 |
197 | # Grouping the document tree into LaTeX files. List of tuples
198 | # (source start file, target name, title,
199 | # author, documentclass [howto, manual, or own class]).
200 | latex_documents = [
201 | (master_doc, 'pytorch.tex', 'TexSoup Documentation',
202 | 'Alvin Wan', 'manual'),
203 | ]
204 |
205 |
206 | # -- Options for manual page output ---------------------------------------
207 |
208 | # One entry per manual page. List of tuples
209 | # (source start file, name, description, authors, manual section).
210 | man_pages = [
211 | (master_doc, 'TexSoup', 'TexSoup Documentation',
212 | [author], 1)
213 | ]
214 |
215 |
216 | # -- Options for Texinfo output -------------------------------------------
217 |
218 | # Grouping the document tree into Texinfo files. List of tuples
219 | # (source start file, target name, title, author,
220 | # dir menu entry, description, category)
221 | texinfo_documents = [
222 | (master_doc, 'TexSoup', 'TexSoup Documentation',
223 | author, 'TexSoup', 'One line description of project.',
224 | 'Miscellaneous'),
225 | ]
226 |
227 |
228 | # Example configuration for intersphinx: refer to the Python standard library.
229 | intersphinx_mapping = {
230 | 'python': ('https://docs.python.org/', None),
231 | 'numpy': ('https://docs.scipy.org/doc/numpy/', None),
232 | }
233 |
234 | # -- A patch that prevents Sphinx from cross-referencing ivar tags -------
235 | # See http://stackoverflow.com/a/41184353/3343043
236 |
237 | from docutils import nodes
238 | from sphinx.util.docfields import TypedField
239 | from sphinx import addnodes
240 |
241 |
242 | def patched_make_field(self, types, domain, items, **kw):
243 | # `kw` catches `env=None` needed for newer sphinx while maintaining
244 | # backwards compatibility when passed along further down!
245 |
246 | # type: (List, unicode, Tuple) -> nodes.field
247 | def handle_item(fieldarg, content):
248 | par = nodes.paragraph()
249 | par += addnodes.literal_strong('', fieldarg) # Patch: this line added
250 | # par.extend(self.make_xrefs(self.rolename, domain, fieldarg,
251 | # addnodes.literal_strong))
252 | if fieldarg in types:
253 | par += nodes.Text(' (')
254 | # NOTE: using .pop() here to prevent a single type node to be
255 | # inserted twice into the doctree, which leads to
256 | # inconsistencies later when references are resolved
257 | fieldtype = types.pop(fieldarg)
258 | if len(fieldtype) == 1 and isinstance(fieldtype[0], nodes.Text):
259 | typename = u''.join(n.astext() for n in fieldtype)
260 | typename = typename.replace('int', 'python:int')
261 | typename = typename.replace('long', 'python:long')
262 | typename = typename.replace('float', 'python:float')
263 | typename = typename.replace('type', 'python:type')
264 | par.extend(self.make_xrefs(self.typerolename, domain, typename,
265 | addnodes.literal_emphasis, **kw))
266 | else:
267 | par += fieldtype
268 | par += nodes.Text(')')
269 | par += nodes.Text(' -- ')
270 | par += content
271 | return par
272 |
273 | fieldname = nodes.field_name('', self.label)
274 | if len(items) == 1 and self.can_collapse:
275 | fieldarg, content = items[0]
276 | bodynode = handle_item(fieldarg, content)
277 | else:
278 | bodynode = self.list_type()
279 | for fieldarg, content in items:
280 | bodynode += nodes.list_item('', handle_item(fieldarg, content))
281 | fieldbody = nodes.field_body('', bodynode)
282 | return nodes.field('', fieldname, fieldbody)
283 |
284 | TypedField.make_field = patched_make_field
285 |
--------------------------------------------------------------------------------
/docs/source/data.rst:
--------------------------------------------------------------------------------
1 | Data Structures
2 | ===================================
3 |
4 | .. automodule:: TexSoup.data
5 |
6 | Node
7 | -----------------------------------
8 |
9 | .. autoclass:: TexNode()
10 | :members:
11 |
12 | Expressions
13 | -----------------------------------
14 |
15 | .. autoclass:: TexExpr()
16 | :members:
17 |
18 | .. autoclass:: TexEnv()
19 | :members:
20 |
21 | .. autoclass:: TexCmd()
22 | :members:
23 |
24 | Groups
25 | -----------------------------------
26 |
27 | .. autoclass:: TexGroup()
28 | :members:
29 |
30 | .. autoclass:: BracketGroup()
31 | :members:
32 |
33 | .. autoclass:: BraceGroup()
34 | :members:
35 |
36 | .. autoclass:: TexArgs()
37 | :members:
38 |
39 | Environments
40 | -----------------------------------
41 |
42 | .. autoclass:: TexNamedEnv()
43 | :members:
44 |
45 | .. autoclass:: TexUnNamedEnv()
46 | :members:
47 |
48 | .. autoclass:: TexMathEnv()
49 | :members:
50 |
51 | .. autoclass:: TexDisplayMathEnv()
52 | :members:
53 |
54 | .. autoclass:: TexMathModeEnv()
55 | :members:
56 |
57 | .. autoclass:: TexDisplayMathModeEnv()
58 | :members:
59 |
60 | Text
61 | ----------------------------------
62 |
63 | .. autoclass:: TexText()
64 | :members:
65 |
--------------------------------------------------------------------------------
/docs/source/index.rst:
--------------------------------------------------------------------------------
1 | .. TexSoup documentation master file, created by
2 | sphinx-quickstart on Sat Apr 6 22:08:46 2019.
3 | You can adapt this file completely to your liking, but it should at least
4 | contain the root `toctree` directive.
5 |
6 | TexSoup documentation
7 | ===================================
8 |
9 | TexSoup is a Python3 library for pulling data from :math:`\LaTeX` files. It
10 | turns even invalid sources into a BeautifulSoup-esque structure that you can
11 | navigate, search, and modify.
12 |
13 | .. toctree::
14 | :maxdepth: 1
15 | :caption: Guides
16 |
17 | quickstart
18 | soup
19 | navigation
20 | searching
21 | modification
22 |
23 |
24 | .. toctree::
25 | :maxdepth: 1
26 | :caption: How it Works
27 |
28 | categorizer
29 | tokenizer
30 | parser
31 |
32 | .. toctree::
33 | :maxdepth: 1
34 | :caption: Package Reference
35 |
36 | main
37 | data
38 | utils
39 |
40 | Indices and tables
41 | ==================
42 |
43 | * :ref:`genindex`
44 |
--------------------------------------------------------------------------------
/docs/source/main.rst:
--------------------------------------------------------------------------------
1 | Main Interface
2 | ===================================
3 |
4 | .. automodule:: TexSoup
5 |
6 | .. autofunction:: TexSoup
7 |
--------------------------------------------------------------------------------
/docs/source/modification.rst:
--------------------------------------------------------------------------------
1 | Modification
2 | ===================================
3 |
4 | You can also modify the document using the TexSoup tree, then export the changes
5 | back to a :math:`\LaTeX` file.
6 |
7 | Commands
8 | -----------------------------------
9 |
10 | As mentioned in :ref:`page-soup`, you can change commands and their arguments.
11 |
12 | >>> soup = TexSoup(r'I am \textbf{\large Large and bold}')
13 | >>> cmd = soup.textbf
14 | >>> cmd.name = 'textit'
15 | >>> cmd
16 | \textit{\large Large and bold}
17 |
18 | You can set :code:`.string` for any single-argument command (e.g., :code:`\section`).
19 |
20 | >>> cmd.string = 'corgis are the best'
21 | >>> cmd
22 | \textit{corgis are the best}
23 |
24 | You can do the same for any command in math mode.
25 |
26 | >>> soup2 = TexSoup(r'$$\textrm{math}\sum$$')
27 | >>> soup2.textrm.string = 'not math'
28 | >>> soup2
29 | $$\textrm{not math}\sum$$
30 |
31 | You can also remove any command in-place, by calling :code:`.delete` on it.
32 |
33 | >>> soup2.textrm.delete()
34 | >>> soup2
35 | $$\sum$$
36 |
37 | Arguments
38 | -----------------------------------
39 |
40 | You can modify arguments just as you would a list.
41 |
42 | >>> cmd.args.append('{moar}')
43 | >>> cmd
44 | \textit{corgis are the best}{moar}
45 | >>> cmd.args.remove('{moar}')
46 | >>> cmd
47 | \textit{corgis are the best}
48 | >>> cmd.args.extend(['[moar]', '{crazy}'])
49 | \textit{corgis are the best}[moar]{crazy}
50 | >>> cmd.args = cmd.args[:2]
51 | >>> cmd
52 | \textit{corgis are the best}[moar]
53 |
54 | Use the argument's :code:`.string` attribute to modify the argument's contents.
55 |
56 | >>> cmd.args[0].string = 'no'
57 | >>> cmd
58 | \textit{no}[moar]
59 |
60 | Environments
61 | -----------------------------------
62 |
63 | Use the :code:`.string` attribute to modify any environment with only text content
64 | (i.e., a verbatim or math environment).
65 |
66 | >>> soup = TexSoup(r'\begin{verbatim}Huehue\end{verbatim}')
67 | >>> soup.verbatim.string = 'HUEHUE'
68 | >>> soup
69 | \begin{verbatim}HUEHUE\end{verbatim}
70 | >>> soup = TexSoup(r'$$\text{math}$$')
71 | >>> soup.text.string = ''
72 |
73 | You can add to an environment's contents using list-like operations, like
74 | :code:`.append`, :code:`.remove`, :code:`.insert`, and :code:`.extend`.
75 |
76 | >>> from TexSoup import TexSoup
77 | >>> soup = TexSoup(r'''
78 | ... \begin{itemize}
79 | ... \item Hello
80 | ... \item Bye
81 | ... \end{itemize}''')
82 | >>> tmp = soup.item
83 | >>> soup.itemize.remove(soup.item)
84 | >>> soup.itemize
85 | \begin{itemize}
86 | \item Bye
87 | \end{itemize}
88 | >>> soup.insert(1, tmp)
89 | >>> soup
90 | \begin{itemize}
91 | \item Hello
92 | \item Bye
93 | \end{itemize}
94 |
95 | See :class:`TexSoup.data.TexNode` for more utilities.
96 |
--------------------------------------------------------------------------------
/docs/source/navigation.rst:
--------------------------------------------------------------------------------
1 | Navigation
2 | ===================================
3 |
4 | Here's the :math:`\LaTeX` document from the quickstart guide::
5 |
6 | >>> tex_doc = """
7 | ... \begin{document}
8 | ... \section{Hello \textit{world}.}
9 | ... \subsection{Watermelon}
10 | ... (n.) A sacred fruit. Also known as:
11 | ... \begin{itemize}
12 | ... \item red lemon
13 | ... \item life
14 | ... \end{itemize}
15 | ... Here is the prevalence of each synonym, in Table \ref{table:synonyms}.
16 | ... \begin{tabular}{c c}\label{table:synonyms}
17 | ... red lemon & uncommon \\ \n
18 | ... life & common
19 | ... \end{tabular}
20 | ... \end{document}
21 | ... """
22 | >>> from TexSoup import TexSoup
23 | >>> soup = TexSoup(tex_doc)
24 |
25 | Going Down
26 | -----------------------------------
27 |
28 | Some expressions contain content. For example, environments may contain items.
29 | TexSoup provides attributes for navigating an environment's children.
30 |
31 | Naviate by naming the expression you want. For example, to access italicized
32 | text, use :code:`soup.textit`::
33 |
34 | >>> soup.textit
35 | \textit{world}
36 |
37 | You can use this to select expressions from a specific part of the document.
38 | For example, this retrieves the an item from an itemize environment::
39 |
40 | >>> soup.itemize.item
41 | \item red lemon
42 |
43 |
44 |
45 | Note accessing by name only returns the first result.
46 |
47 | >>> soup.item
48 | \item red lemon
49 |
50 |
51 | To access *all* items, use one of the utilities from :ref:`page-search`, such
52 | as :code:`find_all`::
53 |
54 | >>> soup.find_all('item')
55 | [\item red lemon
56 | , \item life
57 | ]
58 |
59 | An environment's contents are accessible via a list called :code:`contents`.
60 | Note that changing this list in-place will not affect the environment::
61 |
62 | >>> soup.itemize.contents
63 | [\item red lemon
64 | , \item life
65 | ]
66 |
67 | There are several views into an environment's content:
68 |
69 | - :code:`.children`: Nested Tex expressions. Does not include floating text.
70 | - :code:`.contents`: Nested Tex expressions and text. Does not contain whitespace-only text.
71 | - :code:`.expr.all`: Nested Tex expressions and text, regardless of whitespace or not. All information needed to reconstruct the original source.
72 | - :code:`.descendants`: Tex expressions nested inside of Tex expressions.
73 | - :code:`.text`: Used to "detex" a source file. Returns text from all descendants, without Tex expressions.
74 |
75 | If a command has only one required argument, or an environment has only one
76 | child, these values are made available as a :code:`.string`.
77 |
78 | >>> soup.textit.string
79 | 'world'
80 |
81 | Going Up
82 | -----------------------------------
83 |
84 | You can access an experssion's parent with the :code:`.parent` attribute::
85 |
86 | >>> soup.textit.parent
87 | \section{Hello \textit{world}.}
88 |
--------------------------------------------------------------------------------
/docs/source/parser.rst:
--------------------------------------------------------------------------------
1 | Parsing Mechanics
2 | ===================================
3 |
4 | .. automodule:: TexSoup.reader
5 |
6 | Parser
7 | -----------------------------------
8 |
9 | .. autofunction:: read_tex
10 | .. autofunction:: read_expr
11 | .. autofunction:: read_spacer
12 | .. autofunction:: make_read_peek
13 |
14 | Environment Parser
15 | -----------------------------------
16 |
17 | .. autofunction:: read_item
18 | .. autofunction:: unclosed_env_handler
19 | .. autofunction:: read_math_env
20 | .. autofunction:: read_skip_env
21 | .. autofunction:: read_env
22 |
23 | Argument Parser
24 | -----------------------------------
25 |
26 | .. autofunction:: read_args
27 | .. autofunction:: read_arg_optional
28 | .. autofunction:: read_arg_required
29 | .. autofunction:: read_arg
30 |
31 | Command Parser
32 | -----------------------------------
33 |
34 | .. autofunction:: read_command
35 |
--------------------------------------------------------------------------------
/docs/source/quickstart.rst:
--------------------------------------------------------------------------------
1 | Quick Start
2 | ===================================
3 |
4 | The below illustrates some basic TexSoup functions.
5 |
6 | How to Use
7 | -----------------------------------
8 |
9 | Here is a :math:`\LaTeX` document::
10 |
11 | >>> tex_doc = """
12 | ... \begin{document}
13 | ... \section{Hello \textit{world}.}
14 | ... \subsection{Watermelon}
15 | ... (n.) A sacred fruit. Also known as:
16 | ... \begin{itemize}
17 | ... \item red lemon
18 | ... \item life
19 | ... \end{itemize}
20 | ... Here is the prevalence of each synonym, in Table \ref{table:synonyms}.
21 | ... \begin{tabular}{c c}\label{table:synonyms}
22 | ... red lemon & uncommon \\ \n
23 | ... life & common
24 | ... \end{tabular}
25 | ... \end{document}
26 | ... """
27 |
28 | Call :code:`TexSoup` on this string to re-represent this document as a
29 | nested data structure::
30 |
31 | >>> from TexSoup import TexSoup
32 | >>> soup = TexSoup(tex_doc)
33 | >>> soup
34 | \begin{document}
35 | \section{Hello \textit{world}.}
36 | \subsection{Watermelon}
37 | (n.) A sacred fruit. Also known as:
38 | \begin{itemize}
39 | \item red lemon
40 | \item life
41 | \end{itemize}
42 | Here is the prevalence of each synonym, in Table \ref{table:synonyms}.
43 | \begin{tabular}{c c}\label{table:synonyms}
44 | red lemon & uncommon \\ \n
45 | life & common
46 | \end{tabular}
47 | \end{document}
48 |
49 | Here are a few ways to navigate the TexSoup data structure::
50 |
51 | >>> soup.section
52 | \section{Hello \textit{world}.}
53 | >>> soup.section.name
54 | 'section'
55 | >>> soup.section.string
56 | 'Hello \\textit{world}.'
57 | >>> soup.section.parent.name
58 | 'document'
59 | >>> soup.tabular
60 | \begin{tabular}{c c}\label{table:synonyms}
61 | red lemon & uncommon \\ \n
62 | life & common
63 | \end{tabular}
64 | >>> soup.tabular.args[0]
65 | 'c c'
66 | >>> soup.item
67 | \item red lemon
68 |
69 | >>> list(soup.find_all('item'))
70 | [\item red lemon
71 | , \item life
72 | ]
73 |
74 | One task may be to find all references. To do this, simply search for
75 | ``\ref{