Implement PdfPages for backend pgf#10548
Conversation
| for `'Creator'`, `'Producer'` and `'CreationDate'`. They | ||
| can be removed by setting them to `None`. | ||
| """ | ||
| self.outputfile = filename |
There was a problem hiding this comment.
all these attributes should be private unless you explicitly have a reason to make some public.
|
Would be nice to see how hard it is to implement a single MultiPage context for all relevant backends by adding the right methods to the RendererFoo classes. See e.g. https://github.com/anntzer/mplcairo/blob/master/lib/mplcairo/multipage.py as well. But that may be too hard and a separate PR like this can work too. |
|
Yes, a generic multipage interface would be nice, but I wouldn't make it a requirement for this PR. Similarly, I wouldn't worry about implementing pdf metadata in the first version, just note in the documentation that it's not yet supported. The LaTeX |
|
We have tests that check that the output matches a baseline image. I think they currently exist only for the agg, pdf and svg backends, and I wouldn't really call them unit tests since they produce a complete output file and check the output. See https://github.com/matplotlib/matplotlib/tree/master/lib/matplotlib/testing for the infrastructure for the comparison tests. You could extend the pdf conversion to support multipage files, but that might get somewhat tricky. |
| '_file', | ||
| ) | ||
|
|
||
| def __init__(self, filename, keep_empty=True, metadata=None): |
There was a problem hiding this comment.
probably arguments after filename can be made keyword only
| """ | ||
| self._outputfile = filename | ||
| self._n_figures = 0 | ||
| self.keep_empty = keep_empty |
| Finalize this object, running LaTeX in a temporary directory | ||
| and moving the final pdf file to `filename`. | ||
| """ | ||
| self._file.write(r'\end{document}'.encode('utf-8') + b'\n') |
There was a problem hiding this comment.
just use a single literal bytestring
|
I implemented your comments and setting metadata using hyperref |
|
The Tests fail because the file I created in doc/users/next_whats_new is nowhere included. Where should it be included or what should I change? |
|
Add something like this: 2124ac8 |
|
Now the test fails because the lualatex version on travis is ancient. Any idea what to do about that? Edit the |
|
Installing a newer TeX Live on Travis is a possibility but it sounds like it would really slow down the build. Does Appveyor have a sufficiently new luatex? If so, I think we could just check the version and skip the test if it is too old. |
|
The failing Test Looks unrelated. Any idea what happened there? @jkseppan |
|
Yes, the failure looks unrelated. I restarted the test to see if it happens again. |
|
@jkseppan Ok thanks. The tests are passing now. |
| return parse_lualatex_version(output.decode()) | ||
|
|
||
|
|
||
| def parse_lualatex_version(output): |
There was a problem hiding this comment.
that probably doesn't need to be public
| warnings.warn('error getting fonts from fc-list', UserWarning) | ||
|
|
||
|
|
||
| luatex_version_re = re.compile( |
There was a problem hiding this comment.
that definitely doesn't need to be public
| return texsystem if texsystem in texsystem_options else "xelatex" | ||
|
|
||
|
|
||
| def get_lualatex_version(): |
|
@anntzer I made all the version functions/attributes private |
| latex_header = r"""\PassOptionsToPackage{{ | ||
| {metadata} | ||
| }}{{hyperref}} | ||
| \RequirePackage{{hyperref}} |
There was a problem hiding this comment.
any reason why it's not a standard "usepackage[...]{hyperref}"? (perhaps, I dunno)
There was a problem hiding this comment.
Because People might use hyperref in their rc params latex header and like this it avoids the "hyperref loaded with incompatible options" error
There was a problem hiding this comment.
so that's equivalent to "if hyperref is already loaded by the preamble, then merge these options with those passed in the preamble"? (again, just asking)
There was a problem hiding this comment.
Yes, and the user specified options take precedence.
| if self._n_figures == 0: | ||
| self._write_header(*figure.get_size_inches()) | ||
| else: | ||
| if get_texcommand() == 'lualatex': |
There was a problem hiding this comment.
if get_texcommand == lualated and get_lualatex_version > ...?
| np = r'\newpage\pdfpagewidth={}in\pdfpageheight={}in%' | ||
| self._file.write(np.format( | ||
| *figure.get_size_inches() | ||
| ).encode('utf-8') + b'\n' |
There was a problem hiding this comment.
just include the newline in the format-string above?
here it may make sense to just use a bytes literal and %-interpolation
| needs_pdflatex = pytest.mark.skipif(not check_for('pdflatex'), | ||
| reason='pdflatex + pgf is required') | ||
| needs_lualatex = pytest.mark.skipif(not check_for('lualatex'), | ||
| reason='lualatex + pgf is required') |
| .. _pgf-rcfonts: | ||
|
|
||
|
|
||
| Multi-Page PDF Files |
There was a problem hiding this comment.
add entries to doc/api/howto_faq (which mentions the old pdfpages) and examples/misc/multipage_pdf?
|
Thanks for the PR! |
|
@meeseeksdev backport to v3.0 |
|
Something went wrong ... Please have a look at my logs. |
PR Summary
This adds a
PdfPagesclass forbackend_pgfanalogous to the one inbackend_pdfto be able to use the pgf backend with multi page pdfs.Looking forward to reviews
PR Checklist