TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have written a LaTeX math document with lyx (using document ams class), but now my teacher sent me some LaTeX code which should make the style as he wants it.

I tried a few options to insert the LaTeX code, none worked:

1) add (through lyx) the LaTeX code itself - This didn't work, since there were double definitions, both in the lyx default generated LaTeX code, and the LaTeX code I inserted.

2) through MiKTeX TeXworks- I exported my lyx document to LaTeX, and tried to change all the definitions before \begin{document} to the ones my teacher sent me - This didn't compile, complained about missing definitions, xtra, xtra.

3) through bakoma - i tried opening my exported lyx code, and then inserting the code my teacher sent me at the beginning - This actually worked, but the bibliography and figure placement got ruined - the figures were put at the end, and the bibliography disappeared.

Anyone has any ideas ? What should be the right way to tackle my problem? Attached is the code my teacher sent me

%\usepackage[normalem]{ulem} %\usepackage[top=80pt,bottom=80pt, left=85pt, right=85pt]{geometry} %\usepackage{setspace} %\onehalfspacing

\setlength{\evensidemargin}{.25in} \setlength{\textwidth}{6in} \setlength{\topmargin}{-0.4in}

    \hbox to 5.78in {{\sf Randomized Algorithms}
\hfill \sf #2 }
       \hbox to 5.78in { {\Large \hfill #5  \hfill} }
       \hbox to 5.78in { {\em #3 \hfill #4} }

\newcommand{\lecture}[4]{\handout{#1}{#2}{Lecture date: #3}{Scribe: #4}{Lecture #1}}

\textwidth=6in \oddsidemargin=0.25in \evensidemargin=0.25in \topmargin=-0.1in \footskip=0.8in
\textheight=8.00in \setcounter{tocdepth} {3} \setcounter{secnumdepth} {2} \sloppy

\newenvironment{exercise}{\noindent \textbf{Exercise}}{}%[theorem]{Exercise}
\newenvironment{challenge}{\noindent \textbf{Challenge}}{}%[theorem]{Exercise}
\newenvironment{kitbag}{\noindent \textbf{Kitbag Exercise}}{}
\newenvironment{proof}{\noindent \textbf{Proof}}{$\Box$}
\newenvironment{proof-sketch}{\noindent \textbf{Sketch of Proof}}{$\Box$}


\renewcommand{\P}{{\bf P}}
\newcommand{\Px}{\mathop{\bf P\/}}
\newcommand{\E}{{\bf E}}
\newcommand{\Ex}{\mathop{\bf E\/}}

\newcommand{\Var}{{\bf Var}}
\newcommand{\Cov}{{\bf Cov}}
\newcommand{\Varx}{\mathop{\bf Var\/}}


\newcommand{\nsmaja}{\textstyle{\frac{2}{\pi}} \arcsin \rho}


\newcommand{\N}{\mathbb N}
\newcommand{\R}{\mathbb R}
\newcommand{\Z}{\mathbb Z}
\newcommand{\C}{\mathbb C}

\newcommand{\boldG}{{\boldsymbol G}}
\newcommand{\boldQ}{{\boldsymbol Q}}
\newcommand{\boldR}{{\boldsymbol R}}
\newcommand{\boldS}{{\boldsymbol S}}
\newcommand{\boldX}{{\boldsymbol X}}
\newcommand{\bfX}{{\boldsymbol X}}
\newcommand{\boldB}{{\boldsymbol B}}
\newcommand{\boldY}{{\boldsymbol Y}}
\newcommand{\boldZ}{{\boldsymbol Z}}
\newcommand{\boldV}{{\boldsymbol V}}
\newcommand{\boldsigma}{{\boldsymbol \sigma}}
\newcommand{\boldupsilon}{{\boldsymbol \upsilon}}

\newcommand{\littlesum}{{\textstyle \sum}}

\newcommand{\half}{{\textstyle \frac12}}


\def \la      {\langle}
\def \ra      {\rangle}

\renewcommand{\C}{\mathcal C}
\newcommand{\qed}{\hfill $\square$}

\lecture{10}{Moni Naor}{Jan 2, 2011}{Itay Gonshorovitz}

share|improve this question
Welcome to tex.sx! It's not necessary to sign your questions (as there is already a box with your username below it) or to begin them with a greeting. A tip: if you change 1) to 1. etc. the enumeration is automatically formatted. – Martin Scharrer Mar 13 '11 at 22:04
It is very complicated to say what's going on if we don't have your teachers code. E.g. if he uses \documentclass in his template it will clash with the one defined in lyx or your exported document. To say something is "ruined" is not a good problem description either. If you want to have a good answer, you have to show some code here. – Martin H Mar 13 '11 at 22:14
Okay, i edited the question and added some code - I was just trying before to be concise so as to not put too much information in the question. Hope now it will be more clear. – user4165 Mar 13 '11 at 22:56

There's an issue with the Latex file you give: page layout parameters are duplicated, with some, such as topmargin being defined in two different ways.

I've imported this into Lyx without too much bother. Instructions:

  1. Cut and paste an excerpt from the above snippet into the Latex preamble from the DocumentSettings panel, starting from the line \newcommand{\handout}[5]{ and ending before \begin{document}.
  2. On the Fonts tag of the settings panel, set the Base Size to 11pt.
  3. Insert a Tex code block into the document, and paste the body of the Latex file (i.e., inside the begin-end-document environment).

This will then compile.

An issue with this: Lyx will automatically import AMS packages and some others that it knows of, if it sees that you need them, but as I have it, it won't import the other packages defined in the Latex file you gave us. You can paste in the needed \usepackage lines if you need them, but if you use Lyx for writing, you probably will not need these.

share|improve this answer

Have a look into one of the predefined LyX laout files, they all are saved in a directory named layouts and have the file extensions .layout. In LInux they are saved under /usr/share/lyx/. I don't know what directory it is under Windows. Look for the file slides.layout how such a file has to be defined.

However, it is much more simpler to use directly pdflatex instead of running LyX with creating an own layout file ...

share|improve this answer
I doubt that the predefined layouts will include anything useful for the qner. – Charles Stewart Mar 14 '11 at 9:46
@Charles: no, they won't ... – Herbert Mar 14 '11 at 9:57

I had a look through you code and with all those definition that your teacher wants you to use it seems a lot easier to write in code rather than lyx (I know this is not an direct answer to your question.)

However, in order to make this code work (with pdflatex) I came up with this




showframe %show the margin frame
\usepackage{setspace} \onehalfspacing

%Better use the geometry package above
%to define your margins
%\setlength{\evensidemargin}{.25in} \setlength{\textwidth}{6in}

%hyperref should usually be loaded
%as the last package (few exemptions)

    \hbox to 5.78in {{\sf Randomized Algorithms}
\hfill \sf #2 }
       \hbox to 5.78in { {\Large \hfill #5  \hfill} }
       \hbox to 5.78in { {\em #3 \hfill #4} }

\newcommand{\lecture}[4]{\handout{#1}{#2}{Lecture date: #3}{Scribe:
#4}{Lecture #1}}

%Define the margins with the geometry package above!!!
%This is the second time the margins are defined
% \textwidth=6in \oddsidemargin=0.25in \evensidemargin=0.25in    
% \footskip=0.8in
% \parindent=0.0cm

%Maybe use oparskip package
% \parskip=0.3cm
% \textheight=8.00in 

\setcounter{tocdepth} {3}
\setcounter{secnumdepth} {2}

%Sure you want to use sloppy??
% \sloppy


 \lecture{10}{Moni Naor}{Jan 2, 2011}{Itay Gonshorovitz}
\section{Some section}


I noticed that the margins are multiply defined but I think using the geometry package is the right way to go here.

Also look up what the \sloppy command does, I think your document will look better without it.

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.