Adrien
Good evening,
I'm having trouble properly importing Mathematica code into a latex document. I asked this question on a french maths forum, a member of which told me that it would be better to ask the question on the present forum. Here's the link to the page on the french forum:
http://www.les-mathematiques.net/phorum/read.php?10,2176728
I'll translate the message here.
I created a file "exemples.nb" to test the importation of Mathematica into a latex file. Here's a link to download the file:
https://www.meerodrop.com/fr/drop/7b9e84a1-f54a-4877-8731-359e078b0aac
and for those who don't have Mathematica and who would like to open it, here's the link to download the free player of Wolfram:
https://www.wolfram.com/player/
I attached screenshots of the exemples.nb file for those of you who don't want to download the reader.


I first tried to use the listings package; here is the code I typed:
```
\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{amsfonts}
\usepackage{listings}
\usepackage{amssymb}
\begin{document}
\lstset{language=Mathematica}
Extraire des lignes:
\lstinputlisting[language=Mathematica, firstline=6, lastline=8]{exemples.nb}
\end{document}
```
Here's a screenshot of the result after I compiled the file (obviously not what I expected):

and if I don't precise the lines "firstline" and "lastline", the result is even worse and doesn't even fit in a page (so I didn't attached any screenshot).
After trying this I read that the listings package wasn't good to import ".nb" files. I tried typing by hand the formula using the listings package, but the result doesn't look at all like the Mathematica rendering.
In particular, I'd like to obtain:
1) The same fonts as in Mathematica (Mathematica told me that the font for inputs and outputs was "Consolas");
2) The same colors as in the Mathematica input; I noticed some black, gray, blue and a kind of green (like for example for the variable n in the input 10 in my .nb file);
3) The same symbols (I noticed for example that there were "normal" right arrows and right arrows with a dot on the left for graphs relations like in the input 12);
4) The ability to include, if I wish to, the "In[...]=" and "Out[...]=" at the begining of the lines (for now I don't want to include them but I want the possibility to do it in case I change my mind).
I saw multiple ways to include Mathematica code in a latex document on English forums, but none of them seem to answer to the four requirements previously listed, and everything I read seemed very complex to me (it's maybe due to the fact that I'm not a native English speaker; but anyway I didn't fully understand any of the methods that I found on forums).
Except for the graphic output (where I'll obviously import the image file in the tex document), I don't want to resign myself to importing screenshots of the Mathematica code into the tex file.
Has anyone a solution that they could explain to me to import codes from .nb files or to type them manually in latex so that the final rendering is exactly as the screenshots I provided here?
I thank you in advance for your help!