0

I have this without any issues if I use it alone. However if I call it with input or include I get this enter image description here

Why?

closed as unclear what you're asking by jub0bs, Andrew Swann, Claudio Fiandrino, Torbjørn T., texenthusiast Jan 16 '14 at 15:05

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Sorry, but this is not answerable in the current form. An example of code showing the issue is necessary. – egreg Jun 21 '13 at 21:56
  • as egreg says an example is necessary however it is clear that php code has been passed directly to latex so just produces arbitrary errors, just as if latex code had been passed to php. You need to put such code in a verbatim or listings environment or some other similar environment for quoting non-latex material. – David Carlisle Jun 21 '13 at 21:59
7

Reproducing the problem

Let's say, the referenced answer is in file answer.tex. Then a minimal main document would be:

\documentclass{article}
\usepackage{xcolor}
\begin{document}
\input{answer}
\end{document}

That generates tons of errors. let's ignore them with \batchmode (or pressing q at the first error message). The result is:

Problem

Analysis and hints

What happened, you have tried to input a complete LaTeX document inside the body of another. This is not allowed, already the first error messages say this:

! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.1 \documentclass
                  {article}

The PDF output (image above) is the result of LaTeX's/TeX's error recovery – put a frame around, then you can call it "Modern Art". :-)

A preamble (the stuff before \begin{document}) cannot be called after \begin{document}. But you can merge the two preambles. For example, if you need package listings for the second document, but the first document has not loaded it, then add

\usepackage{listings}

to the preamble of the main document. The same applies to the color definitions (\definecolor lines) and the settings (\lstset) for package listings. Put them into the preamble of the main document.

Then in the body (between \begin{document} and \end{document} you can put the body or parts of it of the second document via copy-paste, \input or \include. The latter can only be used for parts of the document that start and ends at page boundaries (e.g. chapters) and cannot be nested.

A scheme for the new main document would be:

  1. Old preamble with \documentclass and packages.
  2. Additional packages (e.g. \usepackage{listings})
  3. Additional settings (e.g. color definitions, \lstset)
  4. \begin{document}
  5. ...
  6. Variant 1: \begin{lstlistings}...\end{lstlistings} with the PHP code inbetween.
  7. Variant 2: The PHP code can be put into a file and included via via \lstinputlisting (see the documentation of listings)
  8. Variant 3: The body of the answer document (between \begin{document} and \end{document} and excluding these markers) can be put into a file that is included via \input.
  9. (Variant 4: \include does not make sense here.)
  10. ...
  11. \end{document}

I hope, it helps a little or specify, what you want to achieve.

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