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

Feature request: share objects that appear multiple times #24

Open
JasonGross opened this issue Jun 2, 2024 · 1 comment
Open

Feature request: share objects that appear multiple times #24

JasonGross opened this issue Jun 2, 2024 · 1 comment

Comments

@JasonGross
Copy link
Contributor

It seems that memoize will re-inlcude memos that have already been included if I have duplicate tikz code in multiple places. (I haven't checked this carefully, so I may be wrong, but one of my pdfs was ~40MB, and when I removed some \input commands that were duplicated in multiple places, leaving only one copy, it shrunk down to ~27MB) If I'm right that memoize doesn't already do this, it would be nice to include the memoized object only once, save it in some box, and reuse the box multiple times if the object appears in multiple places.

@sasozivanovic
Copy link
Owner

First, sorry for a really late response. I was away for most of the summer, and have only now resumed work on Memoize.

Saving some space is always a good idea, and I already knew that PDFs containing externs are quite bloated, so I investigated a bit. And now I'm fairly confused ...

To load an extern, Memoize uses low-level PDF graphics inclusion commands, in the following spirit:

\pdfximage{file.pdf}%
\pdfrefximage\pdflastximage

My plan was to save \pdflastximage in a macro identified by the extern file name, so that another inclusion of the same extern would simply use \pdfrefximage\thatmacro without loading the extern twice via \pdfximage. I've got the code written, it's only a couple of lines, but before I committed anything, I did some testing. And I realized that the size of the PDF (almost) didn't change upon including the same extern twice even before the change!

I then did further tests, simplifying the situation by taking Memoize out of the picture. I repeated the above code in a test document twice, the PDF stays almost the same size (and I'm testing with a file.pdf of 9MB). If I instead include a PNG image twice, the document size doubles. How about that?

\pdfximage{file.png}%
\pdfrefximage\pdflastximage

Could it be that pdfTeX (& LuaTeX, which behaves the same) automatically do the caching you have suggested, at least for PDFs? Can you test this?

Also, can you retest your original problem? Is the issue still there? If so, can you please tell which TeX distro&version are you using? And post an example document here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants