GeneralWeb-based Creation of a LaTeX Textbook

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
spin0za
Posts: 6
Joined: Sat Dec 10, 2011 9:33 pm

Web-based Creation of a LaTeX Textbook

Post by spin0za »

Hi,

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!)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

5gon12eder
Posts: 126
Joined: Sun Feb 13, 2011 8:36 pm

Web-based Creation of a LaTeX Textbook

Post by 5gon12eder »

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
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
spin0za
Posts: 6
Joined: Sat Dec 10, 2011 9:33 pm

Web-based Creation of a LaTeX Textbook

Post by spin0za »

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
Wow. That it exactly what I had in mind. :D How did you do it?
spin0za
Posts: 6
Joined: Sat Dec 10, 2011 9:33 pm

Re: Web-based Creation of a LaTeX Textbook

Post by spin0za »

oops, double post.
Last edited by spin0za on Mon Dec 12, 2011 10:32 pm, edited 1 time in total.
5gon12eder
Posts: 126
Joined: Sun Feb 13, 2011 8:36 pm

Web-based Creation of a LaTeX Textbook

Post by 5gon12eder »

Glad to hear it might help you. You can follow the link http://www.stud.uni-karlsruhe.de/~uscrl/form/. It will show you the source files in the directory and you can save them to your local machine. However, I might remove the website soon (see the concerns below) so I have attached an archive as well.

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 ..."
Please note that the example is very crude and I can't recommend it to be used on a public server for anything serious. The most concerning things are:
  • 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.
The first two problems should be eliminated by using session IDs. (I have never done this but it doesn't sound too difficult.) The last issue seems inherent to the intended purpose. As an alternative, we could simply post the LaTeX source (with all articles yanked in) on a web page and tell the user to save them into a file and then run pdflatex on that file on her own machine.

You might find this helpful in case you don't already know: http://www.w3schools.com/php/

Best
Attachments
form.tar
(20 KiB) Downloaded 219 times
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
spin0za
Posts: 6
Joined: Sat Dec 10, 2011 9:33 pm

Web-based Creation of a LaTeX Textbook

Post by spin0za »

Awesome. I'm installing a personal server so I can test and tweak it. So I guess it is "bbl". ;)

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); ?>
in the lib.php file.
Post Reply