Skip to content
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

Allow adding arbitrary document code #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions tikz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ def __init__(self, tempdir=None, cache=True, opt=None, **kwoptions):
super().__init__(opt=opt, **kwoptions)
# additional preamble entries
self.preamble = []
self.document_codes = []
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please insert a line comment on the line before explaining the purpose of the variable.

Also please call the variable document_code without the s.

# should the created PDF be cached?
self.cache = cache
# create temporary directory for pdflatex etc.
Expand Down Expand Up @@ -1080,6 +1081,9 @@ def usepackage(self, name, options=None):
code += '{' + name + '}'
self.add_preamble(code)

def add_document_code(self, code):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a docstring to the function, in the style of the other docstrings.

self.document_codes.append(code)

def fira(self):
"""
set font to Fira, also for math
Expand Down Expand Up @@ -1117,6 +1121,7 @@ def _update(self):
# document body
codelines += [
r'\begin{document}',
"\n".join(self.document_codes),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nicer to insert the elements of the list instead of the combined string. I believe *self.document_code should do the trick.

self._code,
r'\end{document}']
code = '\n'.join(codelines)
Expand Down