Esempio n. 1
0
    def __init__(self,
                 options=None,
                 arguments=None,
                 seperate_paragraph=False,
                 begin_paragraph=False,
                 end_paragraph=False,
                 **kwargs):
        from pylatex.parameters import Arguments, Options

        if not hasattr(self, 'container_name'):
            self.container_name = self.__class__.__name__.lower()

        if isinstance(arguments, Arguments):
            self.arguments = arguments
        elif arguments is not None:
            self.arguments = Arguments(arguments)
        else:
            self.arguments = Arguments()

        if isinstance(options, Options):
            self.options = options
        elif options is not None:
            self.options = Options(options)
        else:
            self.options = Options()

        self.seperate_paragraph = seperate_paragraph
        self.begin_paragraph = begin_paragraph
        self.end_paragraph = end_paragraph

        super().__init__(**kwargs)
Esempio n. 2
0
    def __init__(self, options=None, arguments=None,
                 seperate_paragraph=False, begin_paragraph=False,
                 end_paragraph=False, **kwargs):
        from pylatex.parameters import Arguments, Options

        if not hasattr(self, 'container_name'):
            self.container_name = self.__class__.__name__.lower()

        if isinstance(arguments, Arguments):
            self.arguments = arguments
        elif arguments is not None:
            self.arguments = Arguments(arguments)
        else:
            self.arguments = Arguments()

        if isinstance(options, Options):
            self.options = options
        elif options is not None:
            self.options = Options(options)
        else:
            self.options = Options()

        self.seperate_paragraph = seperate_paragraph
        self.begin_paragraph = begin_paragraph
        self.end_paragraph = end_paragraph

        super().__init__(**kwargs)
Esempio n. 3
0
class Environment(Container):
    r"""A base class for LaTeX environments.

    This class implements the basics of a LaTeX environment. A LaTeX
    environment looks like this:

    .. code-block:: latex

        \begin{environment_name}
            Some content that is in the environment
        \end{environment_name}

    The text that is used in the place of environment_name is by defalt the
    name of the class in lowercase. However, this default can be overridden by
    setting the environment_name class variable when declaring the class.

    :param name:
    :param options:
    :param arguments:

    :type name: str
    :type options: str or list or \
        :class:`~pylatex.base_classes.command.Options` instance
    :type argument: str or list or \
        :class:`~pylatex.base_classes.command.Arguments` instance
    """
    def __init__(self,
                 options=None,
                 arguments=None,
                 seperate_paragraph=False,
                 begin_paragraph=False,
                 end_paragraph=False,
                 **kwargs):
        from pylatex.parameters import Arguments, Options

        if not hasattr(self, 'container_name'):
            self.container_name = self.__class__.__name__.lower()

        if isinstance(arguments, Arguments):
            self.arguments = arguments
        elif arguments is not None:
            self.arguments = Arguments(arguments)
        else:
            self.arguments = Arguments()

        if isinstance(options, Options):
            self.options = options
        elif options is not None:
            self.options = Options(options)
        else:
            self.options = Options()

        self.seperate_paragraph = seperate_paragraph
        self.begin_paragraph = begin_paragraph
        self.end_paragraph = end_paragraph

        super().__init__(**kwargs)

    def dumps(self):
        """Represent the named container as a string in LaTeX syntax.

        :return:
        :rtype: str
        """

        string = ''

        if self.seperate_paragraph or self.begin_paragraph:
            string += '\n\n'

        string += r'\begin{' + self.container_name + '}'

        string += self.options.dumps()

        string += self.arguments.dumps()

        string += '\n'

        string += super().dumps()

        string += '\n' + r'\end{' + self.container_name + '}'

        if self.seperate_paragraph or self.end_paragraph:
            string += '\n\n'

        return string
Esempio n. 4
0
class Environment(Container):

    r"""A base class for LaTeX environments.

    This class implements the basics of a LaTeX environment. A LaTeX
    environment looks like this:

    .. code-block:: latex

        \begin{environment_name}
            Some content that is in the environment
        \end{environment_name}

    The text that is used in the place of environment_name is by defalt the
    name of the class in lowercase. However, this default can be overridden by
    setting the environment_name class variable when declaring the class.

    :param name:
    :param options:
    :param arguments:

    :type name: str
    :type options: str or list or \
        :class:`~pylatex.base_classes.command.Options` instance
    :type argument: str or list or \
        :class:`~pylatex.base_classes.command.Arguments` instance
    """

    def __init__(self, options=None, arguments=None,
                 seperate_paragraph=False, begin_paragraph=False,
                 end_paragraph=False, **kwargs):
        from pylatex.parameters import Arguments, Options

        if not hasattr(self, 'container_name'):
            self.container_name = self.__class__.__name__.lower()

        if isinstance(arguments, Arguments):
            self.arguments = arguments
        elif arguments is not None:
            self.arguments = Arguments(arguments)
        else:
            self.arguments = Arguments()

        if isinstance(options, Options):
            self.options = options
        elif options is not None:
            self.options = Options(options)
        else:
            self.options = Options()

        self.seperate_paragraph = seperate_paragraph
        self.begin_paragraph = begin_paragraph
        self.end_paragraph = end_paragraph

        super().__init__(**kwargs)

    def dumps(self):
        """Represent the named container as a string in LaTeX syntax.

        :return:
        :rtype: str
        """

        string = ''

        if self.seperate_paragraph or self.begin_paragraph:
            string += '\n\n'

        string += r'\begin{' + self.container_name + '}'

        string += self.options.dumps()

        string += self.arguments.dumps()

        string += '\n'

        string += super().dumps()

        string += '\n' + r'\end{' + self.container_name + '}'

        if self.seperate_paragraph or self.end_paragraph:
            string += '\n\n'

        return string
Esempio n. 5
0
# Create a new document
doc = Document()
with doc.create(Section('Custom commands')):
    doc.append(
        """
        The following is a demonstration of a custom \\LaTeX
        command with a couple of parameters.
        """)

    # Define the new command
    new_comm = Command('newcommand{\\exampleCommand}', options=3,
                       arguments='\\color{#1} #2 #3 \\color{black}')
    doc.append(new_comm)

    # Use our newly created command with different arguments
    doc.append(ExampleCommand(arguments=Arguments('blue', 'Hello', 'World!')))
    doc.append(ExampleCommand(arguments=Arguments('green', 'Hello', 'World!')))
    doc.append(ExampleCommand(arguments=Arguments('red', 'Hello', 'World!')))

with doc.create(Section('Custom environments')):
    doc.append(
        """
        The following is a demonstration of a custom \\LaTeX
        environment using the mdframed package.
        """)

    # Define a style for our box
    mdf_style_definition = Command('mdfdefinestyle',
                                   arguments=['my_style',
                                              'linecolor=#1,\
                                               linewidth=#2,\