How to tell a single *.tex file to produce separate PDFs?
I have a document that's quite long. It uses a recurse function, a bit like this: \starttext \dostepwiserecurse{1}{180}{1}{% \input chapter\recurselevel } \stoptext That produces 180 chapters of content. Anyway, my boss is upset she has to use a table of contents to navigate to the page she wants, and so wants me to split the file into 180 separate files, which somehow is going to be easier to look at. Honestly, she probably still won't ever actually look at it, but that's her requirement. The problem is, I've been splitting the file by using Print --> PDF and choosing a custom print range, and then saving it. If I ned to repeat that 180 times, it not only will have errors, but probably take 5-10 hours. Is there something I can put, like \breakpdf or something that will tell it to start a new PDF file? They can be named something like file1.pdf, file2.pdf, etc. \starttext \dostepwiserecurse{1}{136}{1}{% \input chapter\recurselevel \breakpdf } \stoptext The perhaps "obvious" answer is just make 180 *.tex files, but since the minimal example above is like 0.01% of the complexity of the real file, that isn't so easy... --Joel
On 20/09/2024 04:57, Joel via ntg-context wrote:
Anyway, my boss is upset she has to use a table of contents to navigate to the page she wants, and so wants me to split the file into 180 separate files, which somehow is going to be easier to look at. Honestly, she probably still won't ever actually look at it, but that's her requirement.
what is the difference between scrolling through your single page files folder and scrolling through a single pdf? How about <ctrl-f> too search in the pdf? with mutools you can take a pdf aprt into individual pages. $ mutool --help usage: mutool <command> [options] clean -- rewrite pdf file convert -- convert document create -- create pdf document draw -- convert document trace -- trace device calls extract -- extract font and image resources info -- show information about pdf resources merge -- merge pages from multiple pdf sources into a new pdf pages -- show information about pdf pages poster -- split large page into many tiles sign -- manipulate PDF digital signatures run -- run javascript show -- show internal pdf objects
-----Ursprüngliche Nachricht----- Von: vm via ntg-context
Gesendet: Freitag, 20. September 2024 10:23 An: ntg-context@ntg.nl Cc: vm Betreff: [NTG-context] Re: How to tell a single *.tex file to produce separate PDFs? On 20/09/2024 04:57, Joel via ntg-context wrote:
Anyway, my boss is upset she has to use a table of contents to navigate to the page she wants, and so wants me to split the file into 180 separate files, which somehow is going to be easier to look at. Honestly, she probably still won't ever actually look at it, but that's her requirement.
what is the difference between scrolling through your single page files folder and scrolling through a single pdf?
How about <ctrl-f> too search in the pdf?
with mutools you can take a pdf aprt into individual pages.
$ mutool --help usage: mutool <command> [options] clean -- rewrite pdf file convert -- convert document create -- create pdf document draw -- convert document trace -- trace device calls extract -- extract font and image resources info -- show information about pdf resources merge -- merge pages from multiple pdf sources into a new pdf pages -- show information about pdf pages poster -- split large page into many tiles sign -- manipulate PDF digital signatures run -- run javascript show -- show internal pdf objects
______________________________________________________________ _____________________ If your question is of interest to others as well, please add an entry to
I was going to suggest pdftk which is similar to mutools. You can get boundaries from a the log file and then split the file using these tools. (Search the mailing list: I think that's also something ConTeXt might be able to do natively, but I'm not sure.) Then, you might also consider using a product-component based solution. You'll then be able to process each file indivdually while still having a main file around. The page numbers in the individual file will be incorrect, i.e. always start at 1, but for having a quick look that still might be nice. (Hans or Wolfgang probably know if there is a way to get correct page numbers when using components...) Best, Denis the
Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg- context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror) archive : https://github.com/contextgarden/context wiki : https://wiki.contextgarden.net ______________________________________________________________ _____________________
On 20/09/2024 10:33, denismaier@mailbox.org wrote: indeed:> I was going to suggest pdftk which is similar to mutools. indeed: pdftk document.pdf burst will generate pg_nnnn.pdf individual pdf pg_0001,pdf pg_0002,pdf pg_0003,pdf pg_0004,pdf ...
On Fri, 20 Sep 2024 10:33:55 +0200
Denis Maier via ntg-context
I was going to suggest pdftk which is similar to mutools.
There is also qpdf. However, running a shell script to run context many times is my favorite solution. This question brings up the topic: would it be useful to be able to do the same within context, either using lua or TeX programming? Alan
Joel via ntg-context schrieb am 20.09.2024 um 04:57:
I have a document that's quite long. It uses a recurse function, a bit like this:
\starttext
\dostepwiserecurse{1}{180}{1}{%
\input chapter\recurselevel
}
\stoptext
That produces 180 chapters of content.
Anyway, my boss is upset she has to use a table of contents to navigate to the page she wants, and so wants me to split the file into 180 separate files, which somehow is going to be easier to look at. Honestly, she probably still won't ever actually look at it, but that's her requirement.
The problem is, I've been splitting the file by using Print --> PDF and choosing a custom print range, and then saving it. If I ned to repeat that 180 times, it not only will have errors, but probably take 5-10 hours.
Is there something I can put, like \breakpdf or something that will tell it to start a new PDF file? They can be named something like file1.pdf, file2.pdf, etc.
\starttext
\dostepwiserecurse{1}{136}{1}{%
\input chapter\recurselevel
\breakpdf
}
\stoptext
The perhaps "obvious" answer is just make 180 *.tex files, but since the minimal example above is like 0.01% of the complexity of the real file, that isn't so easy...
You can use the pdf script file but it's slower than mutool or pdftk. mtxrun --script pdf --split file.pdf Wolfgang
-----Ursprüngliche Nachricht----- Von: Wolfgang Schuster
Gesendet: Freitag, 20. September 2024 12:26 An: mailing list for ConTeXt users ; Joel via ntg-context Betreff: [NTG-context] Re: How to tell a single *.tex file to produce separate PDFs? You can use the pdf script file but it's slower than mutool or pdftk.
mtxrun --script pdf --split file.pdf
Where will this split the pdf? At certain headers?
Denis Maier via ntg-context schrieb am 20.09.2024 um 15:05:
-----Ursprüngliche Nachricht----- Von: Wolfgang Schuster
Gesendet: Freitag, 20. September 2024 12:26 An: mailing list for ConTeXt users ; Joel via ntg-context Betreff: [NTG-context] Re: How to tell a single *.tex file to produce separate PDFs? You can use the pdf script file but it's slower than mutool or pdftk.
mtxrun --script pdf --split file.pdf
Where will this split the pdf? At certain headers?
This splits the pdf into single pages and there are no options. Wolfgang
On 9/20/24 04:57, Joel via ntg-context wrote:
[...] The perhaps "obvious" answer is just make 180 *.tex files, but since the minimal example above is like 0.01% of the complexity of the real file, that isn't so easy...
Hi Joel, I tried to recreate a document with chapters that contain a different number of pages each: \setuppagenumbering[alternative=doublesided] \setuphead[chapter][reference=ch\the\numexpr\namedheadnumber{chapter}+1] \starttext \dorecurse{180}{% \startchapter[title={Chapter \namedheadnumber{chapter}}] \dorecurse{\randomnumber{10}{50}} {\input zapf\par} \stopchapter} \stoptext The key above is setting a reference for each chapter, so that they may be retrieved later automatically. Then you should have the pages for any chapter from its reference with the following command: context --pages=ch100 main-file.tex But I must confess, I cannot get this working. I don’t know what I miss. If you are on Unix, generating a bash loop would be similar to (once your main PDF document has been generated): for i in {1..180}; do mutool merge -o chapter-$i.pdf main-file\ "$(context --pages=ch$i main-file)" But for that, you need to know first how "--pages=[reference]" may work. Just in case it might help, Pablo
On Fri, Sep 20, 2024 at 02:57 (+0000), Joel via ntg-context wrote:
I have a document that's quite long. It uses a recurse function, a bit like this:
\starttext
\dostepwiserecurse{1}{180}{1}{% \input chapter\recurselevel
} \stoptext That produces 180 chapters of content. Anyway, my boss is upset she has to use a table of contents to navigate to the page she wants, and so wants me to split the file into 180 separate files, which somehow is going to be easier to look at. Honestly, she probably still won't ever actually look at it, but that's her requirement.
The problem is, I've been splitting the file by using Print --> PDF and choosing a custom print range, and then saving it. If I ned to repeat that 180 times, it not only will have errors, but probably take 5-10 hours. Is there something I can put, like \breakpdf or something that will tell it to start a new PDF file? They can be named something like file1.pdf, file2.pdf, etc. \starttext
\dostepwiserecurse{1}{136}{1}{% \input chapter\recurselevel \breakpdf
} \stoptext The perhaps "obvious" answer is just make 180 *.tex files, but since the minimal example above is like 0.01% of the complexity of the real file, that isn't so easy...
Joel, others have suggested mutool and pdftk, which could be half the solution for you. (I use pdftk for things like this, but I assume mutool is just as good. Either are far less tedious than printing to file.) If the information of the chapter boundaries is available in the log file, a judicious use of grep and a few lines of shell script code might do the trick. Alternatively, you might be able to use a tool like pdfgrep to find the page numbers from the PDF file, and then use a few lines of shell code. If you are a Linux or Mac user, this should be "easy enough". I don't do windows, but now that there is (as I understand it) a bash shell available, you might also be able to use grep and/or pdfgrep there as well. If the log file isn't currently sufficiently helpful, could you add something to your "start a new chapter" command to write a comment into the log file giving you exactly the information you need? Jim
On 20 Sep 2024, at 03:57, Joel via ntg-context
wrote: I have a document that's quite long. It uses a recurse function, a bit like this:
\starttext
\dostepwiserecurse{1}{180}{1}{%
\input chapter\recurselevel
}
\stoptext
That produces 180 chapters of content.
Anyway, my boss is upset she has to use a table of contents to navigate to the page she wants, and so wants me to split the file into 180 separate files, which somehow is going to be easier to look at. Honestly, she probably still won't ever actually look at it, but that's her requirement.
Since you’ve already got the chapter content split into separate \input files ... At the Unix level, use the following script to run Context 180 times specifying a different output file each time: #! /bin/bash for i in {1..180} do context \ --arguments="ChapNo=$i" test.tex \ --result="chapter_$i.pdf” done And at the Context level, test.tex is simply: \starttext \input chapter\env{ChapNo} \stoptext Regards, — Bruce Horrocks Hampshire, UK
I am using Linux, so those tools are available, but Bruce's solution is working great! Just had to make tiny changes to the file.
I had no idea I could send an environment variable to ConTeXt...will be using that a lot from now! Thanks very much everyone for the help!
On Friday, September 20, 2024 at 11:04:47 AM MDT, Bruce Horrocks
On 20 Sep 2024, at 03:57, Joel via ntg-context
wrote: I have a document that's quite long. It uses a recurse function, a bit like this:
\starttext
\dostepwiserecurse{1}{180}{1}{%
\input chapter\recurselevel
}
\stoptext
That produces 180 chapters of content.
Anyway, my boss is upset she has to use a table of contents to navigate to the page she wants, and so wants me to split the file into 180 separate files, which somehow is going to be easier to look at. Honestly, she probably still won't ever actually look at it, but that's her requirement.
Since you’ve already got the chapter content split into separate \input files ... At the Unix level, use the following script to run Context 180 times specifying a different output file each time: #! /bin/bash for i in {1..180} do context \ --arguments="ChapNo=$i" test.tex \ --result="chapter_$i.pdf” done And at the Context level, test.tex is simply: \starttext \input chapter\env{ChapNo} \stoptext Regards, — Bruce Horrocks Hampshire, UK
Hi Bruce, I had an analogous problem a while ago, but with 7 chapter files, which I treated manually… Your solution is a very nice one, thank you for sharing ! For the archives, if one wishes to have the correct chapter number in each separate PDF file, one could change the content of « test.tex » file as follows: \starttext \setupheadnumber[chapter][\cldcontext{\env{ChapNo}-1}] \input chapter-\env{ChapNo}.tex \stoptext Best regards: Otared
On 20 Sep 2024, at 19:04, Bruce Horrocks
wrote: On 20 Sep 2024, at 03:57, Joel via ntg-context
wrote: I have a document that's quite long. It uses a recurse function, a bit like this:
\starttext
\dostepwiserecurse{1}{180}{1}{%
\input chapter\recurselevel
}
\stoptext
That produces 180 chapters of content.
Anyway, my boss is upset she has to use a table of contents to navigate to the page she wants, and so wants me to split the file into 180 separate files, which somehow is going to be easier to look at. Honestly, she probably still won't ever actually look at it, but that's her requirement.
Since you’ve already got the chapter content split into separate \input files ...
At the Unix level, use the following script to run Context 180 times specifying a different output file each time:
#! /bin/bash for i in {1..180} do context \ --arguments="ChapNo=$i" test.tex \ --result="chapter_$i.pdf” done
And at the Context level, test.tex is simply:
\starttext \input chapter\env{ChapNo} \stoptext
Regards, — Bruce Horrocks Hampshire, UK
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror) archive : https://github.com/contextgarden/context wiki : https://wiki.contextgarden.net ___________________________________________________________________________________
Otared Kavian e-mail: otared@gmail.com Phone: +33 6 88 26 70 95
participants (9)
-
Alan Braslau
-
Bruce Horrocks
-
denismaier@mailbox.org
-
Jim
-
Joel
-
Otared Kavian
-
Pablo Rodriguez
-
vm
-
Wolfgang Schuster