Matlab has a feature called publish to latex that runs code and packages the
code and the output into a latex file. I would like to use it to put
examples into my book but I am having trouble importing the latex code into
Lyx.
The problem is that comments get mangled in with code during the import into
Lyx. The latex code works fine; I am able to create a dvi file from it that
is OK.
I am including an example of the latex code and the Lyx file created by
importing it.
Any ideas of how to fix/workaround?
Bob
-----------latex code:--------------
% This LaTeX was auto-generated from an M-file by MATLAB.
% To make changes, update the M-file and republish this document.
\documentclass{article}
\usepackage{graphicx}
\usepackage{color}
\sloppy
\definecolor{lightgray}{gray}{0.5}
\setlength{\parindent}{0pt}
\begin{document}
\subsection*{Contents}
\begin{itemize}
\setlength{\itemsep}{-1ex}
\item make a plot
\end{itemize}
\begin{verbatim}
% matlab2lyx.m
% Sample file to convert to Lyx input
\end{verbatim}
\subsection*{make a plot}
\begin{verbatim}
xs = linspace(0,2*pi);
ys = []; % initialize
for x = xs % a comment
ys(end+1) = sin(x); % another comment
end
plot(xs,ys,'.k');
\end{verbatim}
\includegraphics [width=4in]{matlab2lyx_01.eps}
\end{document}
----------------------------------
------------Lyx file-----------
#LyX file created by tex2lyx 1.5.5
\lyxformat 247
\begin_document
\begin_header
\textclass article
\begin_preamble
% This LaTeX was auto-generated from an M-file by MATLAB.
% To make changes, update the M-file and republish this document.
\...@ifundefined{definecolor}
{\usepackage{color}}{}
\sloppy
\definecolor{lightgray}{gray}{0.5}
\end_preamble
\language english
\inputencoding auto
\font_roman default
\font_sans default
\font_typewriter default
\font_default_family default
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\paperfontsize default
\spacing single
\papersize default
\use_geometry false
\use_amsmath 0
\cite_engine basic
\use_bibtopic false
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation skip
\defskip medskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\end_header
\begin_body
\begin_layout Subsection*
Contents
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Standard
\backslash
setlength{
\backslash
itemsep}{-1ex}
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Itemize
make a plot
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Standard
\backslash
begin{verbatim}
\end_layout
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Standard
% matlab2lyx.m
\end_layout
\begin_layout Standard
\end_layout
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Standard
% Sample file to convert to Lyx input
\end_layout
\begin_layout Standard
\end_layout
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Standard
\backslash
end{verbatim}
\end_layout
\end_inset
\end_layout
\begin_layout Subsection*
make a plot
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Standard
\backslash
begin{verbatim}
\end_layout
\end_inset
xs = linspace(0,2*pi); ys = [];
\begin_inset ERT
status collapsed
\begin_layout Standard
% initialize
\end_layout
\begin_layout Standard
\end_layout
\end_inset
for x = xs
\begin_inset ERT
status collapsed
\begin_layout Standard
% a comment
\end_layout
\begin_layout Standard
\end_layout
\end_inset
ys(end+1) = sin(x);
\begin_inset ERT
status collapsed
\begin_layout Standard
% another comment
\end_layout
\begin_layout Standard
\end_layout
\end_inset
end plot(xs,ys,'.k');
\begin_inset ERT
status collapsed
\begin_layout Standard
\backslash
end{verbatim}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
\begin_inset Graphics
filename matlab2lyx_01.eps
width 4in
\end_inset
\end_layout
\end_body
\end_document
--
View this message in context:
http://n2.nabble.com/Import-Latex-code-with-verbatim-tp2399787p2399787.html
Sent from the LyX - Users mailing list archive at Nabble.com.