is there a way to load a package by command line? I tried:

latex "\RequirePackage{xcolor} \input{myfile.tex}"

but it doesn't work.

I need to load some packages "temporarily", by scripts I wrote, to do some checks on my output files (pdf or dvi).

Edit. I found that the string I use generates the file xcolor.pdf instead of myfile.pdf

As requested, this is my .log shell output:

tmp$ latex "\RequirePackage{xcolor} \input{example.tex}"
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2015/10/01> patch level 2
Babel <3.9m> and hyphenation patterns for 79 languages loaded.
(./example.tex (/usr/local/texlive/2015/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
No file xcolor.aux.
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!{/usr/local/texlive/2015/texmf-var/fonts/map/pdftex/upd
Non-PDF special ignored!
Non-PDF special ignored!] [2
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!] (./xcolor.aux) )</usr/local/texlive/2015/texmf-dist/f
Output written on xcolor.pdf (2 pages, 22276 bytes).
Transcript written on xcolor.log.

and this is the screenshot:

enter image description here

  • 4
    Check if you need double backslashes
    – Johannes_B
    Jun 18, 2017 at 7:50
  • 2
    Could you enlarge on 'doesn't work': it should. Perhaps your shell needs the backslash escaping (often as two backslashes).
    – Joseph Wright
    Jun 18, 2017 at 7:50
  • 1
    Related: tex.stackexchange.com/questions/375512/…
    – Johannes_B
    Jun 18, 2017 at 7:52
  • @JosephWright I get the package.pdf file instead of filename.þdf ones... also with double backslash excaping. Jun 18, 2017 at 8:19
  • @JosephWright Thank you for your hint ;-) Jun 18, 2017 at 9:14

2 Answers 2


Driver mismatch

The file myfile.tex is broken:

tmp$ latex

latex is initialized to generate DVI as output format.


Package xcolor is loaded with DVI driver dvips. Fine.

But then:

Non-PDF special ignored!

map/pdftex.map} ... Output written on xcolor.pdf

The mode switches to PDF and a PDF file is generated. Color specials for DVI have no effect.

The LaTeX document should never change the output mode. Many, many packages relay on a stable output mode. Check the code for changes of \pdfoutput. It may be read (better is the use of package ifpdf), but should not be changed.

Loading a package on the command line

There are packages, that can be loaded before \documentclass using \RequirePackage, see egreg's answer.

Other package require to be loaded after the class. Some of them, can be loaded even quite late in \AtBeginDocument, then the command line would become:

$ pdflatex '\AtBeginDocument{\RequirePackage{xcolor}\pagecolor{yellow}}\input{myfile}'

An alternative is providing a hook in the file myfile.tex. For example, at the right place in the preamble:

\ifx\WithPageColor Y

If \WithPageColor is undefined, the page color setting is ignored. But, it can be defined on the command line:

$ pdflatex '\let\WithPageColor=Y\input{myfile}'

Another variant for the hook in the preamble:


Then on the command line:

$ pdflatex '\newcommand{\PageColorHook}{\usepackage{xcolor}{\pagecolor{yellow}}\input{myfile}'

Yes, that's true: the first input file is used for the name.

How to fix it?

latex -jobname=myfile '\RequirePackage{xcolor}\input{myfile.tex}'

On your system, double quotes may work, on mine they don't.

Why does that happen? When a TeX engine starts with

engine <options> <argument>

(in your case engine is latex)

it looks at what it is fed with. If the <argument> does not start with a backslash, it is considered a file name and essentially the engine executes \input <argument>. Otherwise the engine waits for the first \input instruction and the name of the input file will determine the job name, used for the log file and the output (dvi or PDF).

Note: the \input command is the primitive one.

Since \RequirePackage eventually does \input xcolor.sty, we have that the jobname is set to xcolor because of the rules.

The option -jobname fixes it by disabling the above feature and establishing the jobname at the outset.

There is a big difference between the command line call above and when the input file starts with \RequirePackage. In the latter case, \RequirePackage is seen when a file has already been \input and the jobname decided upon.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .