0

A friend of mine recently moved from Mac to Windows and I have one of his use cases that I am not able to help him transport (in the most mutatis mutandis way for him) to Windows.

Under Mac he was using Mactex with TexShop and Preview and was doing a latex dvisps ps2pdf on a huge tex file using PsTricks to produce a pdf with a thousand of graphs etc. Then, in this pdf file open with Preview (the default Mac pdf viewer), he was cropping a given graph and was saving the crop into a pdf file, and was then including (with includegraphics) this pdf graph into other tex files compiled as pdf.

The resulting quality was perfect, meaning, the graph quality inside the original huge graphs only pdf was identical to the same graph quality in other pdf files. (Up to more than a 4000% zoom.)

Now, he's trying to do the same under windows, and doesn't naturally want to separate his huge graph tex file into thousands of separate one-graph tex files to produce eps files from them and include the eps files where needed. He is using TexMaker and Texmaker's embedded pdf viewer doesn't have a crop function. Windows 10 snipping tool does the job, naturally with an awful quality already without even having to zoom, and acrobat reader (the freeware) doesn't help also.

What would you guys recommand ?

9
  • For quick cropping, I would personally convert a pdf page to svg using pdf2svg (github.com/jalios/pdf2svg-windows/tree/master/dist-64bits), crop it within Inkscape, and do whatever edits I want there, and save it in Inkscape as a pdf. May 22, 2021 at 11:20
  • However, for such a large database, I would make a more systematic approach. I'm thinking about having LaTeX write all the figure's boundaries to a file, and then using another tex file which can extract any figure from the main PDF on demand. Would be much more professional. If you really want that, ask it, and I might give it a go in the next couple of days. May 22, 2021 at 11:25
  • 1
    if the graphs are alone on a page you could use pdfcrop to get a cropped version, and then include one graph with \includegraphics[page=N]{..} May 22, 2021 at 14:07
  • @UlrikeFischer I have tried pdfcrop and quality wise it is ok. Still a (small ? Not so sure) problem though : I cannot succeed in cropping all blank spaces below pictures, nor would I want to do it page by page by calculating what I should etc.
    – Olorin
    May 22, 2021 at 18:08
  • @VincentKuhlmann I am indeed interested in your professional solution, that you propose. (I cannot make pdfcrop crop the blank margins below pictures in the albeit nice solution proposed by @UlrikeFischer so ...)
    – Olorin
    May 23, 2021 at 11:19

1 Answer 1

0

As mentioned in the comments, I've made a package for you which can do this. Currently it requires a manual \cropbox{} around your pspicture. Once we have confirmed the idea works for you, we can automate this.

You need to get the package file, and save it in the same directory as where you want to use it: https://github.com/vkuhlmann/latex-cropcatalog/blob/main/cropcatalog.sty

(Installation instructions also on https://github.com/vkuhlmann/latex-cropcatalog)

Then, add \usepackage{cropcatalog} to the file of your pspicture's, and surround one of the pspicture's with \cropbox{...}. Compile the file. The pdf output should display a red box around the crop zone we have indicated, and a new file ending with _cropcatalog.txt should be created.

Next, create a new .tex file within the same directory, and call it extract.tex for example. Now, if I assume your collection of pspicture's is called mypspictures.tex then you need in the extract.tex the following code:

\documentclass{article}

\usepackage[
    source={mypspictures.pdf},
    catalog={mypspictures_cropcatalog.txt}
]{cropcatalog}

\begin{document}
    \extractAsPage{1}
\end{document}

Change the file names accordingly for a name different than mypspictures.

The package depends on writing positions from your pdf to disk. I think it still work if you go via dvi instead of just issuing pdflatex on your .tex file. But I'm very curious now if things work like this. Let me now!

If things work out, we can improve some things in the package :)

(And yes, I've spent way too much time just making this for you haha, but hope you appreciate it)

4
  • If you have used pspicture properly, then I probably there will be no margins at all left. In case you do want them, or in case the pspicture does include margins which you can't get rid of, that's something for a next version of the package. May 26, 2021 at 14:19
  • Well first thank you very much for your effort and thorough answer. At first sight I would that my friend will find this way to much "tecchy" (he was pdf cropping with a pdf viewer before as I told) but I will give it a try nevertheless. I don't know what you mean by "used pspicture properly", but as far as I remember, a pdfcrop on the pdf of his figures yielded after \includepage curiously only margins below figure, that pdfcrop couldn't take care of in the whole pdf.
    – Olorin
    May 26, 2021 at 16:58
  • @Olorin yeah. don't know what pdfcrop does but you could simply use standalone class, have each figure on its own page, and then simply use \includepdf to extract a single page of it. But I originally envisioned you had pages full of small pictures, and then this would be my way of going about it. May 26, 2021 at 17:29
  • @Olorin The step down in techiness for me would be to use Inkscape to crop. But if you want to stay in the realm of free and good software, then this will always require some techniness. There are a lot of PDF viewers and editors, but most of them are very commercial and not super great. Also LaTeX is an example. Not very easy to use, but if the basics that Word can perform aren't enough, you end up here May 26, 2021 at 17:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .