tectonic icon indicating copy to clipboard operation
tectonic copied to clipboard

Implement pdfcrop as single executable (example of tectonic as library)

Open kpym opened this issue 3 years ago • 8 comments

I do not know rust so I can't do this, but it will be nice if pdfcrop can be implemented as single executable using tectonic (with precompiled binaries for all major platforms). In this way we will be able to use it without heavy latex distribution installed.

And I think that this well be a good example of usage of tectonic as library.

By the way I opened an issue to ask the support of tectonic in pdfcrop.

kpym avatar Feb 10 '21 08:02 kpym

Yes, I find pdfcrop to be a very useful tool, and I've often wished I could install it in a more standalone fashion.

That being said, Tectonic's PDF manipulation code (from xdvipdfmx) is all in C, so this isn't something that can be done straightforwardly in Rust right now. I would like to one day switch all of the PDF routines over to something written in Rust but that would/will be a major undertaking because there are so many features to implement.

Unless I am misunderstanding how pdfcrop works — does it primarily operate by running a TeX engine under the hood?

pkgw avatar Feb 10 '21 13:02 pkgw

That being said, Tectonic's PDF manipulation code (from xdvipdfmx) is all in C, so this isn't something that can be done straightforwardly in Rust right now. I would like to one day switch all of the PDF routines over to something written in Rust but that would/will be a major undertaking because there are so many features to implement.

Is it a problem that part of the library is in C ? You manage to create tectonic CLI, so it should be possible to create a "custom version" of tectonic that do the pdfcrop job, no ?

Unless I am misunderstanding how pdfcrop works — does it primarily operate by running a TeX engine under the hood?

pdfcrop perl script do the following, as far as I understand :

  1. It runs gs to evaluate the minimal media/cropbox possible.
  2. It creates a temp .tex file that crop the the pdf.
  3. It runs PDF/Xe/Lua/TeX to compile this temporary .tex file.

So tectonic is needed only for the final stage.

kpym avatar Feb 10 '21 14:02 kpym

Oh, then yes, this probably wouldn't be too hard to recreate as a small Rust tool. The dependency on the external gs tool is important to note, but this could indeed make for a nice example. If you're interested in learning Rust this could be a great way to start!

pkgw avatar Feb 10 '21 14:02 pkgw

@pkgw Yes, I would like but I'm learning go now and I have no such time for fun these days :( Sorry. I understand if you have no time either.

kpym avatar Feb 10 '21 14:02 kpym

This probably won't rise to the top of my priority list soon, but I like the idea and am happy to mentor anyone who wants to try adding it as an example.

pkgw avatar Feb 12 '21 12:02 pkgw

I have made two versions. It is a standalone one, but it's too big. So I make another one which is embedded with tectonic. I will make a pull request soom

AlongWY avatar Jan 28 '23 09:01 AlongWY

After reading the comment by @pkgw, I would like to express my point of view.

I think that the added value of a rust program that needs tectonic and ghost script to work is very little compared to pdfcrop which already does this (quite well).

My original idea was to write a standalone program that could be dropped anywhere (e.g. in a docker container) and do the job without any configuration or installation (and without network access).

As for the size of such a program, it is obvious that it will be "big". But 11 Mb is not huge by today's standards, where almost every mobile application is bigger. This is the price you pay for having a "just drop and run" tool.

Last but not least, IMO this project should stay completely separate from tectonic, which should stay focused on "compiling".

Thanks @pkgw and @AlongWY for all your work!

kpym avatar Feb 03 '23 12:02 kpym

Yes, I think this is another way to accomplish the feature, perhaps with a different feature to control how it is implemented.

  • "tectonic-vendored"
  • "ghostsript-vendored"

AlongWY avatar Feb 06 '23 11:02 AlongWY