[Tex/LaTex] LyX does not generate pdf

errorslyxpreamble

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}

Best 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{~<>}}
Related Question