# LyX not importing .tex correctly

this is my first time posting on StackExchange so apologies for any formatting mistakes.
I have a raw .tex file from my professor of a set of lecture notes, I'm attempting to combine this with another set of notes that I have from throughout the course written through LyX. I would like to use LyX instead of combining in another TeX editor as I find it much more readable and easier to edit.

When importing from 'File -> Import -> LaTeX (Plain)' only a small portion (3/32 pages) show up in the LyX editor. I have modified the LyX Preamble to match the Preamble of my raw .tex and it is as follows:

\documentclass[12pt]{article}
\topmargin -1mm % -10mm
\oddsidemargin 0mm % 7mm
\evensidemargin 0mm % 7mm
\textwidth 15.5cm
\textheight 22.5cm %
\parindent 0pt

\usepackage{amsmath}
\usepackage{amscd}
\usepackage{amsthm}
\usepackage{amssymb}

\usepackage{tikz}
\usetikzlibrary{positioning, calc}

\setlength{\parindent}{0pt}

\setlength{\parskip}{0pt}

\def\beginpf{\noindent {\bf Proof. }}

\newcommand{\boite}{\mbox{} \hfill $\square$}
\def\endpf{\boite\medskip}

\newcommand{\ndiv}{\hspace{-4pt}\not{\hspace{3pt}|}\hspace{0pt}}

\def\NN{{\mathbb N}}
\def\N{{\mathbb N}}
\def\QQ{{\mathbb Q}}
\def\Q{{\mathbb Q}}
\def\RR{{\mathbb R}}
\def\R{{\mathbb R}}
\def\CC{{\mathbb C}}
\def\C{{\mathbb C}}
\def\ZZ{{\mathbb Z}}
\def\Z{{\mathbb Z}}

\newcommand{\GL}{\mathrm{GL}}
\newcommand{\SL}{\mathrm{SL}}
\newcommand{\OO}{\mathrm{O}}
\newcommand{\ima}{\mathrm{im}}
\newcommand{\Ker}{\mathrm{ker}}
\newcommand{\conj}{\mathrm{conj}}

\def\a{{\bf a}}
\def\e{{\bf e}}
\def\u{{\bf u}}
\def\v{{\bf v}}
\def\w{{\bf w}}
\def\x{{\bf x}}
\def\y{{\bf y}}
\def\z{{\bf z}}
\def\0{{\bf 0}}
\def\gcd{\mathop{\rm gcd}\nolimits}
\def\hcf{\mathop{\rm hcf}\nolimits}
\def\lcm{\mathop{\rm lcm}\nolimits}
\def\mod{\mathop{\rm mod}\nolimits}
\def\ds{\displaystyle}
\def\bb{\begin{bit}}
\def\eb{\end{bit}}
\def\eps{\varepsilon}
\def\LHS{{\rm LHS}}
\def\RHS{{\rm RHS}}
\def\ds{\displaystyle}
\def\pl{\polter{1}}

\swapnumbers
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{prop}[theorem]{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{facts}[theorem]{Facts}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{remarks}[theorem]{Remarks}
\newtheorem{example}[theorem]{Example}
\newtheorem{examples}[theorem]{Examples}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{bit}[theorem]{}

\def\FF{{\mathbb F}}
\providecommand{\abs}[1]{\lvert#1\rvert}
\providecommand{\Norm}[1]{\lVert#1\rVert}

\def\b{{\bf b}}

\def\Span{\mathop{\rm span}\nolimits}

\def\im{\mathop{\rm im}\nolimits}
\def\tr{\mathop{\rm tr}\nolimits}
\def\rank{\mathop{\rm rank}\nolimits}
%\def\ds{\displaystyle}
\def\bp{\begin{pmatrix}}
\def\ep{\end{pmatrix}}

\newcommand{\pile}[2]{\genfrac{}{}{0pt}{}{#1}{#2}}


And then for the body of the .tex file the following imports fine, but the following 3000+ lines do not appear to import correctly:

\begin{document}

\centerline{\Large{\textbf{MATH 2022 Groups and Vector Spaces}}}

\vspace{.1in}

This outline is based on the previous lecturer's lectures notes, and is a useful resource, but not exactly the same as the course as now given (though I have tried to be consistent about notation). You
should take your own notes in lectures, and may use these notes as back-up.

\section{Definition and examples of groups; subgroups and order}

${\mathbb N} = \{0, 1, 2, 3, \ldots\}$, the set of natural numbers (note that some authors omit 0, but I do not).
$\mathbb Z$, $\Q$, $\R$, and $\C$ are the sets of integers, rational numbers, real numbers, and complex numbers respectively. All come with binary operations $+$ and $\times$.

\begin{definition} Fix an integer $n \ge 1$. We let $\Z_n = \{ 0, 1, 2, \ldots, n-1\}$, and we add and multiply members of ${\mathbb Z}_n$ modulo' $n$. That is, we add or multiply two given members of
${\mathbb Z}_n$ as usual, and then find the remainder of the answer on division by $n$. This is called the \emph{ring of integers modulo $n$}.
\end{definition}

\medskip
\textbf{Example.}
$\Z_4 = \{0, 1, 2, 3\}$ and $+$ and $\times$ are given by the tables
\begin{center}
\begin{tabular}{ c | c c c c}
$+$ & $0$ & $1$ & $2$ & $3$ \\
\hline\$-10pt] 0 & 0 & 1 & 2 & 3 \\ 1 & 1 & 2 & 3 & 0 \\ 2 & 2 & 3 & 0 & 1 \\ 3 & 3 & 0 & 1 & 2 \end{tabular} \qquad \begin{tabular}{ c | c c c c} \times & 0 & 1 & 2 & 3 \\ \hline\\[-10pt] 0 & 0 & 0 & 0 & 0 \\ 1 & 0 & 1 & 2 & 3 \\ 2 & 0 & 2 & 0 & 2 \\ 3 & 0 & 3 & 2 & 1 \end{tabular} \end{center} \begin{definition} A \emph{group} is a non-empty set G on which is defined an associative binary operation \circ such that there is an identity e (e \circ x = x and x \circ e = x for all x \in G), and each x \in G has an inverse in G (an element y such that x \circ y = e and y \circ x = e). \end{definition} The full notation is (G, \circ), but if \circ is understood, then we write G for short. Thus to check that G is a group, you have to check four things: \vspace{.1in} G is closed under the operation, the operation is associative there is an identity every element has an inverse \vspace{.1in} (note that G is closed under the operation' means that if x, y \in G then x \circ y \in G; this is not listed as an axiom, since it is part of what is meant by \circ is a binary operation on G'; also notice that you should avoid saying that G is closed', as that means something else - use the {\em whole phrase} G is closed under \circ'). \begin{examples} (1) (\Z_4, +) is a group. It is closed under the operation, since any remainder modulo 4 lies in the set \{0, 1, 2, 3\}. Associative. For example (3 + 2) + 1 = 1 + 1 = 2, while 3 + (2 + 1) = 3 + 3 = 2. In fact it inherits associativity from + for \Z. Identity element 0. The inverses of 0,1,2,3 are 0,3,2,1 respectively. \medskip (2) More generally (\Z_n, +) is a group for any n. \medskip (3) (\Z_4, \times) is not a group. It is closed under the operation as before, and the operation is associative (it inherits it from \Z). The identity element is 1. But 0 has no inverse, since there is no y with 0 \cdot y = 1. \medskip (4) The subset \{1,2,3\} of \Z_4 is not a group under \times, since it is not closed under the operation. \medskip (5) The subset \{1, 3\} of \Z_4 {\em is} a group under \times. It is closed under the operation since 1 \times a = a and 3 \times 3 = 1. It inherits associativity from \times on \Z_4. The identity element is 1. The inverses of 1, 3 are 1, 3 respectively. \medskip (6) (\R,+) is a group. The identity element is 0, and the inverse of x is -x. \medskip (7) (\R,\times) is not a group. It is closed under \times, \times is associative, the identity is 1, but 0 has no inverse. \medskip (8) We define \R^* = \{ x\in \R : x\neq 0\} = \R \setminus \{0\}. Then (\R^*,\times) is a group. The identity is 1, and the inverse of x is 1/x. \medskip (9) (\R,-) is not a group. The operation is not associative, e.g.\ (1-2)-3 = -4 but 1-(2-3) = 2. \end{examples} \begin{definition} We say that a group (G,\circ) is \emph{abelian} if the operation \circ is commutative, that is, x \circ y = y \circ x for all x, y \in G. \end{definition} \medskip \textbf{Examples.} (\Z_4,+), (\R,+), (\R^*,\times) are abelian groups. This next example is not. \begin{example} (The dihedral group D_3) Consider an equilateral triangle XYZ with centroid O. \[ \begin{tikzpicture}[scale=0.8] \coordinate[label=above left:Y] (Y) at (0,0); \coordinate[label=above right:Z] (Z) at (4,0); \coordinate[label=above:X] (X) at (2,3.464); \coordinate[label=O] (O) at (2,1.1547); \coordinate[label=below:A] (A) at (2, -0.6); \coordinate[label=right:B] (B) at (3.8,2.1939); \coordinate[label=left:C] (C) at (0.2,2.1939); \draw [dashed] (-0.3, -0.1732) -- (B); \draw [dashed] (4.3, -0.1732) -- (C); \draw [dashed] (A) -- (2,3.5); \draw [line width=1.5pt] (X) -- (Y) -- (Z) -- cycle; \end{tikzpicture}$
The isometries of the plane preserving the triangle are
$\begin{array}{c|l} I & \text{do nothing}\\ R & \text{rotate about O by angle 2\pi/3 (clockwise)}\\ S & \text{rotate about O by angle 2\pi/3 (anticlockwise)}\\ A & \text{reflect in line XO}\\ B & \text{reflect in line YO}\\ C & \text{reflect in line ZO.} \end{array}$
The \emph{dihedral group} $D_3$ is given by the set $D_3 = \{ I, R, S, A, B, C\}$ with the operation $\circ$ given by composition. Specifically, $P \circ Q$ means do $Q$ first, then $P$'.
For example $A \circ R = C$, $R \circ A = B$, $A \circ B = S$. Then $\circ$ gives the following group table (where we write $P \circ Q$ in row $P$, column $Q$).
\begin{center}
\begin{tabular}{ c | c c c c c c }
$\circ$ & $I$ & $R$ & $S$ & $A$ & $B$ & $C$ \\
\hline\\[-10pt]
$I$ & $I$ & $R$ & $S$ & $A$ & $B$ & $C$ \\
$R$ & $R$ & $S$ & $I$ & $B$ & $C$ & $A$ \\
$S$ & $S$ & $I$ & $R$ & $C$ & $A$ & $B$ \\
$A$ & $A$ & $C$ & $B$ & $I$ & $S$ & $R$ \\
$B$ & $B$ & $A$ & $C$ & $R$ & $I$ & $S$ \\
$C$ & $C$ & $B$ & $A$ & $S$ & $R$ & $I$
\end{tabular}
\end{center}
The identity element is $I$. The inverses of $I, R, S, A, B, C$ are $I, S, R, A, B, C$ respectively.
\end{example}


When attempting to remove the

\end{example}

the whole body does import, but then a large amount of errors prevents the document from being rendered, what would you suggest as the simplest fix for this. Additionally (although this is a minor problem in the long run) when imported there is still a large amount of LaTeX code environments present, what is the simplest way of cleaning these up. Thanks in advance and again, apologies for any formatting errors/unnecessary parts.

• Unfortunately it is quite complicated to parse arbitrary LaTeX. LyX has its own format, so it has to parse LaTeX and convert it to LyX's format, and it's common for there to be errors. – scottkosty Jan 14 at 18:51
• LyX can make x things that know how export to LaTeX and sometimes how import. But LaTeX can make xplus ∞ things that LyX has no idea how to handle. Hopefully a LaTeX > Open document or conversion with pandoc and then import with LyX will simplify enough the document to be mostly digestible for LyX without lost all document structures and text format. – Fran Jan 15 at 1:49