+
Skip to content

Version Bump + Docs #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TexSoup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from TexSoup.tex import read
from TexSoup.data import TexNode

__version__ = '0.3.0'
__version__ = '0.3.1'


# noinspection PyPep8Naming
Expand Down
94 changes: 92 additions & 2 deletions docs/source/modification.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,95 @@
Modification
===================================

.. note:: This guide is coming soon. In the meantime, please see the package
reference for a :class:`TexSoup.data.TexNode`.
You can also modify the document using the TexSoup tree, then export the changes
back to a :math:`\LaTeX` file.

Commands
-----------------------------------

As mentioned in :ref:`page-soup`, you can change commands and their arguments.

>>> soup = TexSoup(r'I am \textbf{\large Large and bold}')
>>> cmd = soup.textbf
>>> cmd.name = 'textit'
>>> cmd
\textit{\large Large and bold}

You can set :code:`.string` for any single-argument command (e.g., :code:`\section`).

>>> cmd.string = 'corgis are the best'
>>> cmd
\textit{corgis are the best}

You can do the same for any command in math mode.

>>> soup2 = TexSoup(r'$$\textrm{math}\sum$$')
>>> soup2.textrm.string = 'not math'
>>> soup2
$$\textrm{not math}\sum$$

You can also remove any command in-place, by calling :code:`.delete` on it.

>>> soup2.textrm.delete()
>>> soup2
$$\sum$$

Arguments
-----------------------------------

You can modify arguments just as you would a list.

>>> cmd.args.append('{moar}')
>>> cmd
\textit{corgis are the best}{moar}
>>> cmd.args.remove('{moar}')
>>> cmd
\textit{corgis are the best}
>>> cmd.args.extend(['[moar]', '{crazy}'])
\textit{corgis are the best}[moar]{crazy}
>>> cmd.args = cmd.args[:2]
>>> cmd
\textit{corgis are the best}[moar]

Use the argument's :code:`.string` attribute to modify the argument's contents.

>>> cmd.args[0].string = 'no'
>>> cmd
\textit{no}[moar]

Environments
-----------------------------------

Use the :code:`.string` attribute to modify any environment with only text content
(i.e., a verbatim or math environment).

>>> soup = TexSoup(r'\begin{verbatim}Huehue\end{verbatim}')
>>> soup.verbatim.string = 'HUEHUE'
>>> soup
\begin{verbatim}HUEHUE\end{verbatim}
>>> soup = TexSoup(r'$$\text{math}$$')
>>> soup.text.string = ''

You can add to an environment's contents using list-like operations, like
:code:`.append`, :code:`.remove`, :code:`.insert`, and :code:`.extend`.

>>> from TexSoup import TexSoup
>>> soup = TexSoup(r'''
... \begin{itemize}
... \item Hello
... \item Bye
... \end{itemize}''')
>>> tmp = soup.item
>>> soup.itemize.remove(soup.item)
>>> soup.itemize
\begin{itemize}
\item Bye
\end{itemize}
>>> soup.insert(1, tmp)
>>> soup
\begin{itemize}
\item Hello
\item Bye
\end{itemize}

See :class:`TexSoup.data.TexNode` for more utilities.
14 changes: 14 additions & 0 deletions docs/source/soup.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _page-soup:

Soup
===================================

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

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

To output the soup, you can call :code:`str()` on a :class:`TexSoup.data.TexNode` object, or any nested
data structure.

>>> soup4
\begin{itemize}\item hullo\end{itemize}\end{enumerate}
>>> str(soup4)
'\\begin{itemize}\\item hullo\\end{itemize}\\end{enumerate}'
>>> soup4.item
\item hullo
>>> str(soup4.item)
'\\item hullo'

Kinds of Objects
------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def run_tests(self):
sys.exit(errno)


VERSION = '0.3.0'
VERSION = '0.3.1'

setup(
name="TexSoup",
Expand Down
6 changes: 6 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ def test_def_item():
assert soup.item is not None


def test_grouping_optional_argument():
"""Tests that grouping occurs correctly"""
soup = TexSoup(r"\begin{Theorem}[The argopt contains {$]\int_\infty$} the square bracket]\end{Theorem}")
assert len(soup.Theorem.args) == 1


##############
# FORMATTING #
##############
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载