Skip to content

Commit e9e89cf

Browse files
authored
Version Bump + Docs (#110)
* fixes #106 version bump request * finished basic guides (added modification) * added crazy opt arg test from plastex/plastex#129
1 parent 5133486 commit e9e89cf

File tree

5 files changed

+114
-4
lines changed

5 files changed

+114
-4
lines changed

TexSoup/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from TexSoup.tex import read
88
from TexSoup.data import TexNode
99

10-
__version__ = '0.3.0'
10+
__version__ = '0.3.1'
1111

1212

1313
# noinspection PyPep8Naming

docs/source/modification.rst

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,95 @@
11
Modification
22
===================================
33

4-
.. note:: This guide is coming soon. In the meantime, please see the package
5-
reference for a :class:`TexSoup.data.TexNode`.
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.

docs/source/soup.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _page-soup:
2+
13
Soup
24
===================================
35

@@ -23,8 +25,20 @@ You can also ask TexSoup to tolerate :math:`\LaTeX` errors. In which case,
2325
TexSoup will make a best-effort guess::
2426

2527
>>> soup4 = TexSoup(r'\begin{itemize}\item hullo\end{enumerate}', tolerance=1)
28+
>>> soup4
2629
\begin{itemize}\item hullo\end{itemize}\end{enumerate}
2730

31+
To output the soup, you can call :code:`str()` on a :class:`TexSoup.data.TexNode` object, or any nested
32+
data structure.
33+
34+
>>> soup4
35+
\begin{itemize}\item hullo\end{itemize}\end{enumerate}
36+
>>> str(soup4)
37+
'\\begin{itemize}\\item hullo\\end{itemize}\\end{enumerate}'
38+
>>> soup4.item
39+
\item hullo
40+
>>> str(soup4.item)
41+
'\\item hullo'
2842

2943
Kinds of Objects
3044
------------------------------------

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def run_tests(self):
3131
sys.exit(errno)
3232

3333

34-
VERSION = '0.3.0'
34+
VERSION = '0.3.1'
3535

3636
setup(
3737
name="TexSoup",

tests/test_parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@ def test_def_item():
361361
assert soup.item is not None
362362

363363

364+
def test_grouping_optional_argument():
365+
"""Tests that grouping occurs correctly"""
366+
soup = TexSoup(r"\begin{Theorem}[The argopt contains {$]\int_\infty$} the square bracket]\end{Theorem}")
367+
assert len(soup.Theorem.args) == 1
368+
369+
364370
##############
365371
# FORMATTING #
366372
##############

0 commit comments

Comments
 (0)