# How can I use a usepackage only for one section?

I need 2 different usepackages: one for a floatchart ( http://www.texample.net/tikz/examples/simple-flow-chart/) and one for my whole document.

.

For the Floatchart:

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}


For my document:

\usepackage[pdftex]{graphicx}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


If I insert both, texmaker says: option clash for package graphicx and for package inputenc.

What can I do? Can I specify the usepackage for the floatchart only for the floatchart?

• The flowchart cannot be made with \usepackage[utf8]{inputenc} instead? – Romain Picot Jul 8 '14 at 6:51
• In this case (assuming that you can not get rid of the clash by adapting the options), you should write your flowchart in an own document of the standalone class. You may load the standalone-package in your main document in order to include the spare files easily. Or you just include the pre-compiled pdfs. – LaRiFaRi Jul 8 '14 at 6:56
• Remove the pdftex option for graphicx, and remove \usepackage[latin1]{inputenc}. – Torbjørn T. Jul 8 '14 at 7:01
• Be aware, that the option pdftex should not be given. – Johannes_B Jul 8 '14 at 7:02
• You can convert floatchart from latin1 coding to utf8. There are external tools to do this (iconv), online tools but some text editors can also make this conversion (texworks does it). – Ignasi Jul 8 '14 at 8:31

I don't know where this [pdftex] habit originates but you don't need to use it. You can read a few answers on this site too about it but in a nut shell, most modern packages know what the current driver is and they can decide. Providing a fixed option is only looking for trouble.

In your example, TikZ already loads graphicx so you don't need to do anything. Just load TikZ and you are good to go. If for some reason you don't want to include the package then include it as a picture.

So, using

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows}


and it should work for both sections. Instead of font and input encoding, I would go with LuaTeX though.

Conflict between color, graphicx and libertine

Option clash when using graphicx and tikz packages

Is it possible to load a TikZ library locally?

Both option/package combinations can be easily merged:

\usepackage{graphicx}


Of course different drivers cannot be used for parts of the document. If you are using pdflatex, then option pdftex can be omitted, because the standard graphics.cfg of MiKTeX or TeX Live is able to detect pdfTeX in PDF mode and sets the option appropriately.

\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage[T1]{fontenc}


The input encoding for the document:

\usepackage[utf8]{inputenc}


If the flow chart is using latin1, then the input encoding can be changed in the mid of the document via \inputencoding:

\usepackage[utf8]{inputenc}
...
\begin{document}
% UTF-8 stuff
% ...
\inputencoding{latin1}
% Flowchart with text in latin1
% ...
\inputencoding{utf8}
% Back to UTF-8


Or latin1 can be set locally:

\begingroup
\inputencoding{latin1}
% Flowchart with text in latin1
% ...
\endgroup
% back to previous input encoding

\usepackage[something]{inputenc}


tells LaTeX which input encoding to expect. This is the encoding that your document is saved in.

You cannot save your document in two different encodings. (You could make two copies - one per encoding - but a single file has a single encoding.)

So you cannot use both

\usepackage[utf8]{inputenc}


and

\usepackage[latin1]{inputenc}


for the same document as you are effectively telling LaTeX, 'Hey, I'm a file encoded in both latin1 and utf8!' and that obviously cannot be true. Encodings apply to files and not parts of files.

If you really need the flow chart in a different encoding (but why?), then you would need to compile it as a distinct document and include it as a graphic, for example, or as a PDF if it is a stand-alone page.

Note that your package calls are dealing with two distinct kinds of encoding: input encodings (inputenc) and output/font encodings (fontenc).

\usepackage[something]{fontenc}


specifies the output font encodings to be used. Unlike input encodings, you can switch between these encodings within a document. (In fact, LaTeX will essentially do this whatever you do when it sets up the fonts for mathematics.)

\iftrue
%\iffalse
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\else
\usepackage{graphicx}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\fi


In this case the first three are used. If you comment \iftrue and uncomment \iffalse it will be the other way round.

• This will not permit to have a package only for one section or I haven't understand your point :/ – Romain Picot Jul 8 '14 at 7:16