question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Container subclass to generate part of my LaTeX report

See original GitHub issue

I have a LaTeX project which consist of many .tex files. I want to use PyLaTeX to only generate one of these files, so I basically DON’T want PyLaTeX to create the Document etc.

I want something that works like this:

from pylatex.base_classes.containers import Container

class GeneralContainer(Container):
    _latex_name = 'generalcontainer'
    def __init__(self):
        super().__init__()
        
    def dumps(self):
        s = ''
        for child in self:
            if isinstance(child, str):
                s_ = child
            else:
                s_ = child.dumps()
            s+=s_
        return s

Usage: Fill the container with PyLaTeX objects and then save this to a plain .tex file

content= Text()
content.append(...)
content.generate_tex('file.tex')

And than I can use this content in whichever way I want in LaTeX

\section{Section bla bla bla}
\input{file}

Basically I need this kind of general container which is already a subclass of Container, does such one exist? Is this a desired use case for PyLaTeX?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
JelteFcommented, Sep 16, 2020

I just released 1.4.0 with the Fragment class included.

1reaction
JelteFcommented, Sep 15, 2020

You can probably use the Fragment class that this PR introduces: https://github.com/JelteF/PyLaTeX/pull/292

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing your own class - Overleaf, Online LaTeX Editor
Sometimes the best option to customize a document is to write a new class from scratch. This article explains the main structure and...
Read more >
How to override a subclass of book to get TOC on even page ...
I am trying to get my table of contents on a verso page (i.e., an even-numbered one). I have seen several threads on...
Read more >
The very short guide to typesetting with LATEX
1. Create your document using any suitable plain-text editor with LATEX controls, eg TEXshop (Mac), TEXnicCenter (Win), Kile (Linux) ...
Read more >
Rolling your own Document Class: Using LATEX to keep ...
This paper describes what the code in the article document class file does and suggests solutions to some of the popular requirements for...
Read more >
HTML and CSS Tutorial - Nanyang Technological University
This is the reason that I combine both the HTML and CSS in this article as they are inseparable. To create an OMO...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found