1

I have a large book with many chapters, lots figures and tikz pictures and some of them have really large file sizes (over 100MB). I utilize https://docs.google.com/viewer?url= to get the chapters from GitHub and visualize the pdf on the browser. The problem is that there is a limit on file size of 20MB.

I currently use ghostscript to reduce file sizes, and I've recently discovered arara and read in the documentation that there is support for gs. I was wondering if it was possible to create a conditional using arara to run gs only if the file size is over 20MB.

1
  • Yes, it is. It's not too difficult but you have to create an own rule or rely on implementation details. I'm sure @PauloCereda will provide an answer soon :)
    – TeXnician
    Aug 7 '21 at 20:29
2

It's definitely possible to exploit the underlying File class. For testing purposes, let us create a file of exactly 20MB:

[paulo@cambridge ~] $ truncate -s 20MB foo.dat
[paulo@cambridge ~] $ ls -l foo.dat
-rw-rw-r--. 1 paulo paulo 20000000 ago  8 10:46 foo.dat

Now, let's create a very simple TeX file:

Hello
\bye

And add the following directives:

% arara: pdftex if toFile('foo.dat').length() <= 20000000
% arara: xetex if toFile('foo.dat').length() < 20000000

We are exploiting toFile(...), which returns a File object and then using the length() method which gives us the total of bytes of that particular file. The first directive will run PDFTeX if, and only if, the size of foo.dat is less or equal 20MB (20,000,000 bytes). Similarly, the second directive will run XeTeX if, and only if, the size of foo.dat is less than 20MB.

Running arara test.tex will give us

[paulo@cambridge ~] $ arara test.tex
  __ _ _ __ __ _ _ __ __ _
 / _` | '__/ _` | '__/ _` |
| (_| | | | (_| | | | (_| |
 \__,_|_|  \__,_|_|  \__,_|

Processing "test.tex" (size: 129 B, last modified: 08/08/2021
11:00:38), please wait.

(PDFTeX) PDFTeX engine .................................. SUCCESS

Total: 0.45 seconds

which should be expected, as the size of foo.dat is equal to 20MB. This trick could be used in the rule context as well. Hope this could act as a starting point. ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.