General ⇒ Web-based Creation of a LaTeX Textbook
Web-based Creation of a LaTeX Textbook
As a uni prof, each semester, I need to create an anthology of texts that will be studied. I use LaTeX and create great-looking textbooks. I have all the required articles in tex format in a folder, and a master file with all the formatting and a bunch of /input commands. So all I have to do is change the input commands, press Compile and I get a nice DIY textbook.
So far so good.
I've decided to automate the process a bit, i.e. create a web-based interface that would let me (or another teacher from the faculty) select which articles will be in the anthology, then create a PDF with the result. That way, anyone from the faculty could create customized anthologies without any knowledge of LaTeX.
I would like to have some input from people with a good understanding of LaTeX. So far, the solution I'm thinking of is a PHP script with drop-down menus for selecting the texts, then send the command for compiling on the server, then displaying the resulting PDF.
Is there a simpler solution for what I want to do? Any idea or tips on how I could code this?
Thanks alot!
(also: 1st post!)
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
-
- Posts: 126
- Joined: Sun Feb 13, 2011 8:36 pm
Web-based Creation of a LaTeX Textbook
I have made a little demonstration. If it is something close to what you have in mind, I'll be glad to give more explanation.
It is my first attempt to use PHP so I'll be glad for feedback from more skilled people.
Best
Web-based Creation of a LaTeX Textbook
Wow. That it exactly what I had in mind.5gon12eder wrote:I don't know if this will be useful to you but I liked the idea and was excited if I could do that. (Also, I wished that my teachers would be that concerned about preparing high quality supplementary material.)
I have made a little demonstration. If it is something close to what you have in mind, I'll be glad to give more explanation.
It is my first attempt to use PHP so I'll be glad for feedback from more skilled people.
Best

Re: Web-based Creation of a LaTeX Textbook
-
- Posts: 126
- Joined: Sun Feb 13, 2011 8:36 pm
Web-based Creation of a LaTeX Textbook
The idea is the following:
- The user fills out the form (form.php). Plain HTML would do for this purpose but I wanted the bibliography to be generated dynamically, so it got a PHP script.
- This information is now passed to another script (download.cgi) that takes the information, writes a corresponding .tex file and runs pdflatex (currently twice) on the server. When pdflatex ends with returncode 0 it displays a link to the generated PDF document, otherwise an error message.
- The second script needs privileges to spawn a child process. On my university's servers, this means I have to write a CGI script (but it is still just PHP).
- Both scripts use functions defined in lib.php.
- Many people might prefer to put both scripts into a single page so you can correct your input and reprocess the document without using the browser's "back" button. This would be easily implemented.
- To avoid hard-coding as much as possible, the written .tex file contains just as little code as possible. The rest is done within preamble.txt.
- However, the list of articles and their citations are hard-coded in lib.php. It might be desirable to parse a .bib file or so to generate them dynamically. Then the person maintaining the list wouldn't need to know PHP.
- To provide a minimum level of security against shell-injection, the text inputs in the form are sanitized to eliminate LaTeX escape characters. This will stop evil "users" from putting code into the fields that will cause arbitrary damage but it will also certainly freak out good-intended users who will expect getting a title reading "ab initio computations for applications in organic chemistry." but instead end up with the ridiculous phrase "\emph{ab initio} computations for ..."
- The file written is always the same (reading.tex / reading.pdf). Hence the service won't be able to handle simultaneous requests.
- The files are not deleted afterwards. If somebody (accidentally) puts in sensible information, it will be visible for the public on the web.
- We are running a script that needs write privileges on the hosting server.
You might find this helpful in case you don't already know: http://www.w3schools.com/php/
Best
- Attachments
-
- form.tar
- (20 KiB) Downloaded 218 times
Web-based Creation of a LaTeX Textbook

Update: up and running. I'm trying it out with my own tex files. I didn't have to use a cgi so I just renamed download.cgi as download.php. Also had to remove the shebang lines since I'm using wampp (on win7).
One last thing: the script sent a "notice" error message for each file that is not selected to be in the anthology. It went away by adding
Code: Select all
<?php error_reporting (E_ALL ^ E_NOTICE); ?>