I want to include some Mathematica code in my tex file. For that I'm using this solution.
As an example:
\documentclass[12pt,a4paper]{book}
\usepackage{graphicx}
\usepackage{bm}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{listings,xcolor}
\lstset{language=Mathematica}
\lstset{basicstyle={\sffamily\footnotesize},
numbers=left,
numberstyle=\tiny\color{gray},
numbersep=5pt,
breaklines=true,
captionpos={t},
frame={lines},
rulecolor=\color{black},
framerule=0.5pt,
columns=flexible,
tabsize=2,
mathescape,
commentstyle=\color{gray}
}
\begin{document}
\begin{lstlisting}[language=Mathematica,caption={Loglrt computes the loglikelihood for a sample, under the null.}]
loglrt[tetas_, sigmaest_, y_, n_] := Log[Times @@ (1/(Sqrt[2 * Pi] * sigmaest) *
E^(-(y[[2 ;; n]] - tetas[[2]] - tetas[[1]] * y[[1 ;; n - 1]])^2 / (2 * sigmaest^2)))];
\end{lstlisting}
\end{document}
This works when the formulas are already in the latex document that will serve as a basis to produce the pdf.
However,
I'm writing my thesis like a book. I write each chapter separately and then input them in the main tex file. Similarly to what I usually do I wrote in the main tex:
\documentclass[12pt,a4paper]{book}
\usepackage{graphicx}
\usepackage{bm}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{listings,xcolor}
\lstset{language=Mathematica}
\lstset{basicstyle={\sffamily\footnotesize},
numbers=left,
numberstyle=\tiny\color{gray},
numbersep=5pt,
breaklines=true,
captionpos={t},
frame={lines},
rulecolor=\color{black},
framerule=0.5pt,
columns=flexible,
tabsize=2,
mathescape
}
\DeclarePairedDelimiter{\ceil}{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\graphicspath{ {./Pictures} }
\begin{document}
\frontmatter
%\setcounter{section}{1}
\input{title.tex}
\input{dedication.tex}
\tableofcontents
\mainmatter
\chapter{Introduction}
\input{Introduction.tex}
\appendix
\chapter{Mathematica Code}
\input{Mathematica Code2.tex}
\backmatter
\end{document}
In this case, my tex compiler says that it cannot find the file "Mathematica Code2.tex", which is ver strange since it exists in the same folder as "Introduction.tex" and all the other tex files being inputed in the main body...
Any help would be appreciated.
MathematicaCode2.tex– Nov 27 '14 at 15:28\input{"Mathematica Code2"}with quotes, but not having a space makes things a lot easier. – David Carlisle Nov 27 '14 at 15:48\usepackage{grffile}allows it to have spaces in filenames. – MaxNoe Nov 27 '14 at 17:43