tectonic
tectonic copied to clipboard
Implement pdfcrop as single executable (example of tectonic as library)
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
.
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?
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 :
- It runs
gs
to evaluate the minimal media/cropbox possible. - It creates a temp
.tex
file thatcrop
the thepdf
. - It runs PDF/Xe/Lua/TeX to compile this temporary
.tex
file.
So tectonic
is needed only for the final stage.
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 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.
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.
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
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!
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"