I want to add some lines in LyX preamble but not finding how to do that. If anyone help that would be much appreciated.

See this is my preamble:



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.



Now I want to add some lines between last two lines;

**I want to put some lines here**

Kindly help; how can I do that?

PS: when I go Document > Settings... > LaTeX preamble; that put those required lines before \usepackage{babel} which I don't want.

2 Answers 2


Another way would be to tell LyX to not load babel, instead loading it 'manually':

  1. Document --> Settings --> Language: For Language package select None.

    enter image description here

  2. In the LaTeX preamble, also in the document settings, add e.g.


    followed by whatever you need.

  • If i do this, unfortunately document give error while compiling... (Error:babe package doesn't found)
    – faiza
    Mar 10, 2015 at 12:13
  • @faiza babe is not the same as babel. Mar 10, 2015 at 12:20

LyX is somewhat restrictive in what it allows you to do and where. However, if you want something just before \begin{document}, perhaps it's sufficient to contain such content as part of the document hook

\AtBeginDocument{<your stuff here>}

While this will reside above your \usepackage{babel} instance, it will be executed after it as forms part of the initiation in the \document macro (or \begin{document}). Note that this does not allow you to add packages via \usepackage, as they can only be called from within the preamble, and the \AtBeginDocument hook falls outside this scope.

If you really want to insert packages after babel and before \begin{document}, the following hack does that:

\let\oldusepackage\usepackage% Store \usepackage
\renewcommand{\usepackage}[2][]{% Update \usepackage
  \oldusepackage[#1]{#2}% Regular \usepackage
  \ifnum\pdfstrcmp{#2}{babel}=0\relax% If babel is loaded, also do the following:

When you view the Document > LaTeX Log, you'll see geometry and array loaded after babel.

  • its not making required changes in the document if it resides before \usepackage{babe1}
    – faiza
    Mar 9, 2015 at 18:40
  • I want to put these lines before: \usepackage[lmargin=1.5cm,rmargin=1.5cm]{geometry} \usepackage{array} \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
    – faiza
    Mar 9, 2015 at 18:41
  • @faiza: Is that all? Why don't you include that as part of the regular LaTeX preamble? That is, why do you have include this after \usepackage{babel}?
    – Werner
    Mar 9, 2015 at 18:48
  • Because it is not making desired changes if i put it somewhere else...
    – faiza
    Mar 9, 2015 at 18:54
  • @faiza: It's true that you can't put \usepackage{<package>} inside \AtBeginDocument, as \usepackage can only be used inside the preamble (and the \AtBeginDocument hook is executed outside the preamble). When I include your code as part of the regular LaTeX preamble I get the desired output, even with babel. So what are you doing differently?
    – Werner
    Mar 9, 2015 at 18:59

You must log in to answer this question.

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