3

I am using PHP on my server to create a latex table from a database, which is working fine. The problem I have now is getting that into my latex document. I thought that giving it the path would allow it to get the file from the web and input it like normal but that doesn't work and I've been unable to find anything online about doing this sort of thing.

Here is an example of what I'm trying to accomplish:

\documentclass{article}
\begin{document}
\input{http://example.com/generated-latex.php}
\end{document}
  • 1
    You can call wget from your LaTeX call, download the file, rename it and compile it. – Johannes_B Jun 10 '15 at 11:51
  • Sorry, but I don't quite get what you mean. I googled "latex wget" and found nothing. I'm using TeXworks on my windows laptop to compile the document (probably should have specified that, my bad). – LEGEND383 Jun 10 '15 at 12:05
  • wget is a command line tool to download stuff to the local harddrive. – Johannes_B Jun 10 '15 at 12:07
  • Was hoping for something other than downloading the file or copy/pasting from a web browser, like maybe an extension for the input command to allow web paths, but it looks like that's too much to ask for :( Oh well, thanks anyway – LEGEND383 Jun 10 '15 at 12:25
  • 1
    You need to somehow get this to TeX, a simple write to the commandline to download and read the file is the easiest it gets. If it is just for one or two occurrences, manually downloading will cause less of a headache. LuaTeX on the other hand might do it easier. – Johannes_B Jun 10 '15 at 12:29
6

You could make use of the “piped \input” feature. For example, this is a MWE that inputs from the standard output of a cat command: the same idea can be applied to other commands, and, in principle, also to wget:

\begin{filecontents}{myTempFile.tex}
\section{A test}
This is a test.\par
\end{filecontents}

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}

\begin{document}
\input{|"cat myTempFile.tex"}
\end{document}

Of course, for this example I have generated the temporary file by means of a filecontents environment.

Edit

By way of example, let us \input from the standard output of the date command as well:

\begin{filecontents}{myTempFile.tex}
\section{A test}
This is a test.\par
\end{filecontents}

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}

\begin{document}
\input{|"cat myTempFile.tex"}
\input{|date}
\end{document}

Here is the result:

Output of second example


Addition

Re-reading this answer, that I had posted more than a year ago, I realized that I had never completed it as I intended to. Just to convince yourself that the answer is “Yes, it is possible to input a file from the web”, try compiling a source file containing just the following, single line:

\input{|"curl --stderr /dev/null http://www.math.unipd.it/\string~mezzetti/Gustavo/Ludic/CDP/presentazione.tex"}

This example uses curl, but it is easy to adapt it to use wget instead. Remember that you have to enable the “full shell escape” feature, in order for this to work.

  • So he could use the wget code wget -O - http://example.com/generated-latex.php to redirect wget to stdout and then use the pipe to insert it directly. – Juri Robl Jun 10 '15 at 12:50
  • @JuriRobl: Exactly. Btw, I’m not very familiar with wget, but is it -o or -O the option for redirecting the output to a file (to stdout, in case - is given as the file name)? EDIT: forget my question, I’ve just checked: -o is for redirecting the log messages. – GuM Jun 10 '15 at 12:55
  • Yes, I think it should work that way (had to look at the docs, last time I used it was some time ago). – Juri Robl Jun 10 '15 at 12:57
  • I tried \input{|date} and got the error that it couldn't find the file "|date", am I missing something? – LEGEND383 Jun 10 '15 at 13:20
  • 1
    It might be worth pointing out that doing this with anything other than a trusted, secure file would be An Extremely Bad Idea Indeed. Running cat on an arbitrary local file is already risky, of course. – cfr Aug 3 '17 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.