# Is setting up my own Latex webservice feasible_



## kagi3624 (Oct 26, 2020)

Hello, I have a freeBSD server and I have live-tex installed. I wonder if it is possible to set up a latex web service: Send a tex file to the server and get a pdf file back. What is the effort of this and what would I need to do? My experience with (remote) servers is level: noob. Thx.


----------



## hruodr (Oct 26, 2020)

That should be very simple with a CGI script, but not very usable. When one writes a document
with TeX/LaTeX, one does it interactive. One runs TeX, see the result or the errors, change the source file, see it again, etc. To do that over the WEB would be not very pleasant.


----------



## mark_j (Oct 26, 2020)

Depends. Do you want to upload tex file & display the pdf? Something like SOAP can facilitate that. Is this web server accessible to the internet?
You will have to write the upload web page in some language, python, php, perl etc. The code would process the file & display the pdf. There used to be pdflib in php that did this; I think it's deprecated, though what replaced I do not know.
Something like PHP can run a script you write to convert latex into pdf very easily. Likewise for other languages.
Your options are endless.


----------



## hruodr (Oct 26, 2020)

mark_j said:


> Something like SOAP can facilitate that.



No, no. Something like SOAP would make this trivial task infinitely more complicated.

And pdflib is not necessary, LateX is based on pdftex and it can generate pdf. You could
also run dvips and ps2pdf in the script.

And better not to use php. Sure it may make things easy, but also makes easy to lose the
overview.


----------



## kagi3624 (Oct 26, 2020)

Thank you for the answers. I actually don't need to get it desplayed by the server, it would be enough if I get a pdf back to the local computer. Also I need not to worry much about the tex itserf since it will be a template where I just change some text.


----------



## hruodr (Oct 26, 2020)

If you not really need TeX, but a similar markup language, and want to see the result in the
browser, there is a more complicated solution, but perhaps nicer for the user:









						MathJax - Wikipedia
					






					en.wikipedia.org
				




I managed for example to integrate it with the fossil wiki.


----------



## hruodr (Oct 26, 2020)

kagi3624 said:


> Also I need not to worry much about the tex itserf since it will be a template where I just change some text.



Then you do not need to send the whole TeX file. You can keep the template in the server
and make a html form with the fields to be introduced in the template. The cgi script may
also test if the data on the fields is adequate.


----------



## kagi3624 (Oct 26, 2020)

Can you please push me in the right direction how to set up my own server. I can do it with soap or RUST if needed. I understand what it is, meaning I know how to write requests and parse responses as JSON or xml but I don't know how to set up my own server. thx.


----------



## hruodr (Oct 26, 2020)

Neither SOAP nor JSON nor XML needed. Only html, cgi and a language of your choice
for writing a program that runs in your server. Your program must be able to write
to standard output, to call latex, to write temporary files, read files and environment
variables. To learn HTML and CGI see for example here:






						HTML Made Really Easy
					

Tutorial-- teaches HTML quickly, clearly, and concisely, with          examples.  Teaches core understanding of HTML as well as direct          practical knowledge.



					www.jmarshall.com
				









						CGI Made Really Easy
					

Quick, simple tutorial for CGI programming.  Learn to write CGI          scripts fast, if you're already a programmer.  Examples in Perl and C;         mailer script included.



					www.jmarshall.com
				




Google for apache and see how to make it run CGI scripts. For example:



			Apache Tutorial: Dynamic Content with CGI - Apache HTTP Server Version 2.4
		


In the Content-Type header returned by your script it must be announced that a
pdf file is being outputted.


----------



## mark_j (Oct 26, 2020)

kagi3624 said:


> Thank you for the answers. I actually don't need to get it desplayed by the server, it would be enough if I get a pdf back to the local computer. Also I need not to worry much about the tex itserf since it will be a template where I just change some text.


Then this is just simple POST/GET stuff.
However, you haven't answered my question. Is this exposed to the internet? If so, the answer is much more complicated because you must protect input from nefarious people. If not, then you can do whatever sloppy programming you want.

Basically you need:
1. Post your information to the web server.
2. Some application (PHP, Perl) takes that information and either hands it off to a processor application or does it itself using internal libraries.
3. The application in point 2 presents a page to you with the pdf ready for download. (Beware pdf being displayed in the browser: https://webdesign.tutsplus.com/tutorials/quick-tip-using-the-html5-download-attribute--cms-23880)

So, you need a web server, Apache, Nginx, Lighttpd etc. and you need a server side language.

Perhaps look at these:





						PHP - GET & POST Methods
					

PHP - GET & POST Methods,  There are two ways the browser client can send information to the web server.




					www.tutorialspoint.com
				











						PHP Form Handling
					

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.




					www.w3schools.com


----------



## kagi3624 (Oct 26, 2020)

Hello Mark, I have a freeBSD on vultr that I want to use to practice, but the goal is to use it on my own freeBSD server in a network. So no, it won't be exposed to the internet.


----------



## hruodr (Oct 26, 2020)

mark_j said:


> However, you haven't answered my question. Is this exposed to the internet? If so, the answer is much more complicated because you must protect input from nefarious people.


Indeed. People could run a nefarious TeX script. To offer a form that check the fields and
construct the TeX script in the server with the template and contents of the fields is 
much better that checking an arbitrary TeX script.


----------



## mark_j (Oct 26, 2020)

kagi3624 said:


> Can you please push me in the right direction how to set up my own server. I can do it with soap or RUST if needed. I understand what it is, meaning I know how to write requests and parse responses as JSON or xml but I don't know how to set up my own server. thx.


Ok, let's get the naming conventions understood first.

What do you mean by server? Do you mean just setting up FreeBSD to a point where you can log in? That is install it?
Do you mean a server in regard to the so-called FAMP stack - FreeBSD, Apache, MySql and PHP?

In the case of the former, just download the ISO for the architecture you're running (let's say AMD64). You then go to the handbook section of the freebsd.org site https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/bsdinstall-pre.html

In the case of the latter, install the OS, run pkg update, then pkg search then install Apache, MySQL and PHP (Perl, Python, whatever).


----------

