I installed the MacTEX package, and want to use the listings package for pretty printing code. According to the TeX Live Utility, the package is installed (I tried re-installing it as well). However, when I try typesetting via TeXShop, I get an error:

l.4 \usepackage

Does anyone know what the problem is?

EDIT: Complete document code:

Lorem ipsum.
  • Can you show your code? – Juri Robl Sep 7 '14 at 10:23
  • @JuriRobl Sure! Edited now. – Vegard Stikbakke Sep 7 '14 at 10:25
  • Welcome to TeX.SX! The error message is before the l.4 line and starts with !; can you show it? – egreg Sep 7 '14 at 10:25
  • 1
    You can't use \usepackage after \begin{document}, move it befor it. – Juri Robl Sep 7 '14 at 10:25
  • @JuriRobl Oh, wow! That was it, thanks a lot! – Vegard Stikbakke Sep 7 '14 at 10:27

The compiler often tries to give you a hint what you can do to fix it. Sometimes it's very cryptic and involves wizards (If you really absolutely need more capacity, you can ask a wizard to enlarge me.), in this case it's just

LaTeX Error: Can be used only in preamble

which basically means you can't use it in your document part (after \begin{document}), but before it. That's your preamble, and is the only place where you can use some commands like \usepackage.

| improve this answer | |

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.