diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 9f1bb8c9..1d192ec9 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -14,6 +14,8 @@ This version might not be stable, but to install it use:: pip install git+https://github.com/JelteF/PyLaTeX.git +- Add ``MultiCols`` class based on the LaTeX ``multicol`` package. + 1.4.1_ - `docs <../v1.4.1/>`__ - 2020-10-18 ------------------------------------------- diff --git a/examples/multicols.py b/examples/multicols.py new file mode 100644 index 00000000..f939a953 --- /dev/null +++ b/examples/multicols.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +"""This example shows the multicols functionality.""" + +from pylatex import Document, Section, Itemize, MultiCols + +if __name__ == '__main__': + doc = Document() + + # create a bulleted "itemize" list inside a 2 column mutlicols like the below: + # \begin{itemize} + # \item The first item + # \item The second item + # \item The third etc \ldots + # \end{itemize} + + with doc.create(Section('2 column list')): + with doc.create(MultiCols(2)): + with doc.create(Itemize()) as itemize: + itemize.add_item("the first item") + itemize.add_item("the second item") + itemize.add_item("the third etc") + + doc.generate_pdf('multicols', clean_tex=False) diff --git a/pylatex/__init__.py b/pylatex/__init__.py index 66377e50..c05ace1a 100644 --- a/pylatex/__init__.py +++ b/pylatex/__init__.py @@ -27,6 +27,7 @@ from .position import Center, FlushLeft, FlushRight, MiniPage, TextBlock, \ HorizontalSpace, VerticalSpace from .labelref import Marker, Label, Ref, Pageref, Eqref, Autoref, Hyperref +from .multicols import MultiCols from ._version import get_versions __version__ = get_versions()['version'] diff --git a/pylatex/multicols.py b/pylatex/multicols.py new file mode 100644 index 00000000..9c9b5a85 --- /dev/null +++ b/pylatex/multicols.py @@ -0,0 +1,24 @@ +#! /usr/bin/env python3 +"""This module implements LaTeX multicol package.""" + +from pylatex.utils import NoEscape +from .base_classes import Environment +from .package import Package + + +class MultiCols(Environment): + """The class that represents multicols.""" + + packages = [Package('multicol')] + + def __init__(self, number): + """ + Initialize class instance. + + Args + ---- + number: int + The number of columns in multicols. + """ + self.number = number + super().__init__(arguments=NoEscape(number)) diff --git a/tests/test_args.py b/tests/test_args.py index 5d9696d1..f4119460 100755 --- a/tests/test_args.py +++ b/tests/test_args.py @@ -21,7 +21,7 @@ SmallText, FootnoteText, TextColor, FBox, MdFramed, Tabu, \ HorizontalSpace, VerticalSpace, TikZCoordinate, TikZNode, \ TikZNodeAnchor, TikZUserPath, TikZPathList, TikZPath, TikZDraw, \ - TikZScope, TikZOptions, Hyperref, Marker + TikZScope, TikZOptions, Hyperref, Marker, MultiCols from pylatex.utils import escape_latex, fix_filename, dumps_list, bold, \ italic, verbatim, NoEscape @@ -305,6 +305,12 @@ def test_tikz(): repr(dr) +def test_multicols(): + + multicols = MultiCols(2) + repr(multicols) + + def test_lists(): # Lists itemize = Itemize()