[Tex/LaTex] Adding the own format to lyx

lyx

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

%&latex
\documentclass[11pt]{article}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{latexsym}
\usepackage{epsfig}
\usepackage{hyperref}
%\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}
\setlength{\textheight}{8.5in}

\newcommand{\handout}[5]{
   \renewcommand{\thepage}{#1-\arabic{page}}
   \noindent
   \begin{center}
   \framebox{
      \vbox{
    \hbox to 5.78in {{\sf Randomized Algorithms}
\hfill \sf #2 }
       \vspace{4mm}
       \hbox to 5.78in { {\Large \hfill #5  \hfill} }
       \vspace{2mm}
       \hbox to 5.78in { {\em #3 \hfill #4} }
      }
   }
   \end{center}
   \vspace*{4mm}
}

\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
\parindent=0.0cm
\parskip=0.3cm
\textheight=8.00in \setcounter{tocdepth} {3} \setcounter{secnumdepth} {2} \sloppy


\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{question}[theorem]{Question}
\newtheorem{answer}[theorem]{Answer}
%\newtheorem{exercise}[theorem]{Exercise}
\newtheorem{example}[theorem]{Example}
\newtheorem{algorithm}[theorem]{Algorithm}
%\newtheorem{exercise}[theorem]{Exercise}
\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$}

\newcommand{\ignore}[1]{}

\renewcommand{\Pr}{{\textup{Pr}}}
\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{\bits}{\{-1,1\}}

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

\newcommand{\Inf}{\mathrm{Inf}}
\newcommand{\I}{\mathrm{I}}
\newcommand{\J}{\mathrm{J}}

\newcommand{\eps}{\epsilon}
\newcommand{\lam}{\lambda}
\newcommand{\N}{\mathbb N}
\newcommand{\R}{\mathbb R}
\newcommand{\Z}{\mathbb Z}
\newcommand{\C}{\mathbb C}
\newcommand{\CalE}{{\mathcal{E}}}

\newcommand{\CalU}{{\mathcal{U}}}
\newcommand{\F}{{\mathcal{F}}}
\newcommand{\CalC}{{\mathcal{C}}}
\newcommand{\CalM}{{\mathcal{M}}}
\newcommand{\CalR}{{\mathcal{R}}}
\newcommand{\CalS}{{\mathcal{S}}}
\newcommand{\CalV}{{\mathcal{V}}}
\newcommand{\CalX}{{\boldsymbol{\mathcal{X}}}}
\newcommand{\CalG}{{\boldsymbol{\mathcal{G}}}}
\newcommand{\CalY}{{\boldsymbol{\mathcal{Y}}}}
\newcommand{\CalZ}{{\boldsymbol{\mathcal{Z}}}}
\newcommand{\CalF}{{\mathcal{Z}}}
\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{\hone}{{\boldsymbol{H1}}}
\newcommand{\htwo}{\boldsymbol{H2}}
\newcommand{\hthree}{\boldsymbol{H3}}
\newcommand{\hfour}{\boldsymbol{H4}}
\newcommand{\poly}{\boldsymbol{poly}}


\newcommand{\sgn}{\mathrm{sgn}}
\newcommand{\Maj}{\mathrm{Maj}}
\newcommand{\Thr}{\mathrm{Thr}}
\newcommand{\littlesum}{{\textstyle \sum}}

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

\newcommand{\Stab}{\mathbb{S}}
\newcommand{\StabThr}[2]{\Gamma_{#1}(#2)}
\newcommand{\TestFcn}{\Psi}

\renewcommand{\phi}{\varphi}
\def \la      {\langle}
\def \ra      {\rangle}

\newcommand{\x}{\mathbf{x}}
\renewcommand{\o}{\mbox{o}}
\renewcommand{\O}{\mbox{O}}
\newcommand{\h}{\mathbf{H}}
\newcommand{\va}{\mbox{var}}
\renewcommand{\d}{\mbox{d}}
\renewcommand{\C}{\mathcal C}
\newcommand{\qed}{\hfill $\square$}
\begin{document}

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



\end{document}

Best Answer

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.

Related Question