# LyX does not generate pdf

I have just actualize my LyX version from LyX 1.6 to LyX 2.2 and now I am unable to get a pdf preview (when clicking the "eyes" button). The thing is that the following message appears:

LaTeX Error: Two \documentclass or \documentstyle commands.
Undefined control sequence.
LaTeX Error: Missing \begin{document}.
Package inputenc Error: Keyboard character used is undefined.
Extra }, or forgotten $Missing$ inserted.
Missing glyphs!
You can't use 'macro parameter character #' in horizontal mode
Missing number, trated as zero.
Package babel Error: You haven't loaded the option spanish yet.


(Many of these appear a several number of times).

I think the problem has something to do with the LaTeX preamble of the file, but first, is the same I used for LyX 1.6 and second, I have been trying some preambles suggested in this website but do not work either.

What I have been using is:

\usepackage[spanish, es-tabla]{babel}
\usepackage{fancyhdr} % activamos el paquete
\pagestyle{fancy} % seleccionamos un estilo
\lhead{My name} % texto izquierda de la cabecera
\chead{} % texto centro de la cabecera
\rhead{\thepage} % número de página a la derecha
\lfoot{My Name} % texto izquierda del pie
\cfoot{} % imagen centro del pie
\rfoot{\thepage} % texto derecha del pie
\renewcommand{\headrulewidth}{0.4pt} % grosor de la línea de la cabecera
%\renewcommand{\footrulewidth}{0.4pt} % grosor de la línea del pie


I would be grateful if someone could help me (I really need LyX for my work and have been blocked because of this problem for a couple of days so far...).

EDIT: in answer to Torbjørn,

% Vista preliminar del código fuente

%% LyX 2.2.2 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[twoside,spanish]{extarticle}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{geometry}    \geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=2cm,rmargin=2cm,headheight=2cm,headsep=2cm,footskip=1.5cm}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}

\makeatletter
\@ifundefined{date}{}{\date{}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\documentclass{<class>}
\begin{document}
\end{document}
\makeatother
\usepackage{babel}
\addto\shorthandsspanish{\spanishdeactivate{~<>}}
\begin{document}
\end{document}

• Welcome to TeX SX! Could you post a minimal code that doesn't compile? Also, does updating Lyx also update the TeX distribution that's in the background? – Bernard Dec 17 '16 at 16:03
• The error "Two \documentclass commands" sounds as if your preamble is really messed up. Did you add manually a \documentclass command? Can you compile a small (new) hello-world document? – Ulrike Fischer Dec 17 '16 at 16:24
• Sure, this is what I receive when trying to compile a hello world file. – Andrés Salinas Fernández Dec 17 '16 at 16:33
• @AndrésSalinasFernández you quoted example can't work, there is to much missing. Please add a minimal example (or for heavens sake, your complete example). If I compile the above example, I get the error \usepackage before \documentclass. – Jan Dec 17 '16 at 18:05
• @Jan The OP uses LyX, what he showed is probably what he manually added to the preamble, LyX adds the \documentclass and the rest. – Torbjørn T. Dec 17 '16 at 18:07

## 1 Answer

LyX places your text within the appropriate \documentclass ... \begin{document} and \end{document} wrapper without you having to do it manually. It seems like you have the above wrapper contained within your Document > Settings... > LaTeX Preamble. This is apparent since LyX exports the .tex file with the LaTeX Preamble included after

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.


Instead, you should perhaps only have the following in the LaTeX Preamble:

\usepackage{babel}
\addto\shorthandsspanish{\spanishdeactivate{~<>}}