Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TraditionalForm in output cells #51

Open
carlogabrieli opened this issue Mar 1, 2022 · 12 comments
Open

TraditionalForm in output cells #51

carlogabrieli opened this issue Mar 1, 2022 · 12 comments
Labels

Comments

@carlogabrieli
Copy link

Hi,

Is it possible to obtain the Mathematica TraditionalForm in an output cell generated in a Mathematica notebook with MathematicaCellsToTeX and Mmacells?

Thanks

@jkuczm jkuczm added the question label Mar 3, 2022
@jkuczm
Copy link
Owner

jkuczm commented Mar 3, 2022

Yes it's possible. It should more or less work out of the box.

The thing is that TraditionalForm is designed to look like traditional mathematical expressions as produced by ordinary TeX math mode. These packages started as more "code" oriented, and by default mmaCells use TeX verbatim environment with some of math mode features kind of hacked in, so default conversion will not look exactly like TraditionalForm.

For TraditionalForm output Mathematicas built-in TeX export might do a better job than CellToTeX function.

If you could provide some examples of cells that you want to convert, and write what you don't like in default CellsToTeX conversion then I could check what could be done about that.

Maybe some combination of CellsToTeX for input cells and built-in TeX export for for TraditionalForm output cells would work?

@carlogabrieli
Copy link
Author

Thanks for your reply. I'll try a combination of the two. As I have many cells to insert in the book is it possible to omit the cell numbers?

@jkuczm
Copy link
Owner

jkuczm commented Mar 13, 2022

If you want to keep cell labels, just without the numbers, you can use label option. To automatically change labels in all cells you can redefine appropriate cell styles, as shown below. You can put anything you like in the label option, even leave it completely empty, then no labels will be shown.

If you want to completely get rid of labels together with their additional margins, you can switch off list wrappers, that are internally used to provide labels, by using uselist=false option.

\documentclass[12pt]{article}
\usepackage{mmacells}


\begin{document}

Default behavior:
\begin{mmaCell}{Input}
a+a
\end{mmaCell}
\begin{mmaCell}{Output}
2 a
\end{mmaCell}


Redefined cell styles:
\mmaDefineCellStyle{Input}{
  style/Code,
  formatted,
  annotations=false,
  mathreplacements=bold,
%   label={In[\mmaCellIndex]:=},
  label={In[]:=},
}
\mmaDefineCellStyle{Output}{
  indexed,
  formatted,
  mathreplacements=light,
  morelst={style=MathematicaFrontEndOut},
%   label={Out[\mmaCellIndex]\mmaCellForm*=},
  label={Out[]\mmaCellForm*=},
}
\begin{mmaCell}{Input}
a+a
\end{mmaCell}
\begin{mmaCell}{Output}
2 a
\end{mmaCell}

No \verb|list| wrappers at all:
\mmaSet{uselist=false}
\begin{mmaCell}{Input}
a+a
\end{mmaCell}
\begin{mmaCell}{Output}
2 a
\end{mmaCell}

\end{document}

output

@carlogabrieli
Copy link
Author

Thank you very much! I try

@carlogabrieli
Copy link
Author

I tried to combine your style with the the Mathematica LaTeX conversion:

Compute the following integer powers of the imaginary unit:
\begin{equation*}
\mathrm{i}^{125},, \mathrm{i}^{34},,\frac{1}{\mathrm{i}^5},, \mathrm{i}^{-15}
\end{equation*}
\noindent
this can be easily done evaluating the following cell (the imaginary unit can be entered in \textsc{Mathematica} as \texttt{\bf I}) wherein a list is always delineated by curly braces:

\begin{mmaCell}{Input}
{\mmaSup{\mmaDef{I}}{125},\mmaSup{\mmaDef{I}}{34},\mmaFrac{1}{\mmaSup{\mmaDef{I}}{5}},\mmaSup{\mmaDef{I}}{-15}}
\end{mmaCell}

\begin{mmaCell}{Output}

\end{mmaCell}{Output}

\begin{doublespace}
\noindent({\mathrm{i},-1,-\mathrm{i},\mathrm{i}})
\end{doublespace}

but I'm not able to insert the output after Out[] keeping the TraditionalForm. How can I do? Thanks

@carlogabrieli
Copy link
Author

I send you a notebook I want to convert for my book (the problem is also with Mathematica fonts e.g. for the imaginary unit). Thank you for your support
Notebook to insert.pdf

@carlogabrieli
Copy link
Author

carlogabrieli commented Mar 14, 2022 via email

@jkuczm
Copy link
Owner

jkuczm commented Mar 14, 2022

I'm not able to insert the output after Out[] keeping the TraditionalForm.

Put relevant code inside mmaCell environment.
You should also change "verbatim environment" to something that is not actually verbatim, this can be done using verbatimenv=... option.

the problem is also with Mathematica fonts e.g. for the imaginary unit

If you're using Unicode-aware engine (xetex, luatex) you can use Mathematica fonts directly with fontspec package. Just define \newfontfamily pointing to proper files in your Mathematica installation directory.
You can also directly use unicode characters: 𝕚 and and instruct TeX to use Mathematica font for them using newunicodechar package.

Putting it together we get:

\documentclass{article}

\usepackage{fontspec}
\usepackage{newunicodechar}
\usepackage{setspace}
\usepackage{mmacells}

% Replace given `Path`s with proper paths on your system.
\newfontfamily\mmarmfamily{Mathematica}[
  Extension = .ttf ,
  Path = /home/jkuczm/local/Wolfram/Mathematica/11.0/SystemFiles/Fonts/TrueType/ ,
  BoldFont = *-Bold ]
\DeclareTextFontCommand{\textmmarm}{\mmarmfamily}
\newfontfamily\mmasffamily{MathematicaSans}[
  Extension = .ttf ,
  Path = /home/jkuczm/local/Wolfram/Mathematica/11.0/SystemFiles/Fonts/TrueType/ ,
  BoldFont = *-Bold ]
\DeclareTextFontCommand{\textmmasf}{\mmasffamily}
\newfontfamily\mmattfamily{MathematicaMono}[
  Extension = .ttf ,
  Path = /home/jkuczm/local/Wolfram/Mathematica/11.0/SystemFiles/Fonts/TrueType/ ,
  BoldFont = *-Bold ]
\DeclareTextFontCommand{\textmmatt}{\mmattfamily}

\newcommand\MathematicalDoubleStruckSmallIWrapper{}
\newunicodechar{𝕚}{\MathematicalDoubleStruckSmallIWrapper{𝕚}}
\newcommand\DoubleStruckItalicSmallIWrapper{}
\newunicodechar{ⅈ}{\DoubleStruckItalicSmallIWrapper{ⅈ}}

\newenvironment{traditionalFormOutputInner}
  {%
    \renewcommand\DoubleStruckItalicSmallIWrapper{\textmmarm}
    \begin{doublespace}%
  }
  {%
    \end{doublespace}%
  }
\mmaDefineCellStyle{Input}{
  style/Code,
  formatted,
  annotations=false,
  mathreplacements=bold,
%   label={In[\mmaCellIndex]:=},
  label=\textit{\color{black!60}In[\textcolor{black!10}{\textbullet}]:=},
  morefv={formatcom*={\renewcommand\MathematicalDoubleStruckSmallIWrapper{\textmmatt}}},
}
\mmaDefineCellStyle{Output}{
  indexed,
  formatted,
  mathreplacements=light,
  morelst={style=MathematicaFrontEndOut},
%   label={Out[\mmaCellIndex]\mmaCellForm*=},
  label=\textit{\color{black!60}Out[\textcolor{black!10}{\textbullet}]=},
  verbatimenv=traditionalFormOutputInner,
}


\begin{document}

\begin{mmaCell}{Input}
\(\Big\{\mmaSup{𝕚}{125},\mmaSup{𝕚}{34},\mmaFrac{1}{\mmaSup{𝕚}{5}},\mmaSup{𝕚}{-15}\Big\}\)
\end{mmaCell}

\begin{mmaCell}{Output}
\(\{ⅈ,-1,-ⅈ,ⅈ\}\)
\end{mmaCell}

\end{document}

which compiles to:
xetex

@carlogabrieli
Copy link
Author

carlogabrieli commented Mar 14, 2022 via email

@carlogabrieli
Copy link
Author

Hi,

Sorry to bother you. Currently I'm using Overleaf and I have trouble loading Mathematica fonts on their cloud. So I give up using Mathematica fonts for now. Please help me to use verbatimenv=... option to obtain an output similar to TraditionalForm. I tried

\mmaSet{uselist=true}
\begin{mmaCell}{Input}
{\mmaSup{\mmaDef{I}}{125},\mmaSup{\mmaDef{I}}{34},\mmaFrac{1}{\mmaSup{\mmaDef{I}}{5}},\mmaSup{\mmaDef{I}}{-15}}
\end{mmaCell}
\begin{mmaCell}{Output}

\end{mmaCell}
({\mathsf{i},-1,-\mathsf{i},\mathsf{i}})

but I'm not satisfied. See the png file for the LaTeX output. Thanks for your help and patience

TraditionalForm

@jkuczm
Copy link
Owner

jkuczm commented Mar 14, 2023

Try:

\documentclass{article}

\usepackage{setspace}
\usepackage{mmacells}

\mmaDefineCellStyle{Input}{
  style/Code,
  formatted,
  annotations=false,
  mathreplacements=bold,
  label=\textit{\color{black!60}In[\textcolor{black!10}{\textbullet}]:=},
}
\mmaDefineCellStyle{Output}{
  indexed,
  formatted,
  mathreplacements=light,
  morelst={style=MathematicaFrontEndOut},
  label=\textit{\color{black!60}Out[\textcolor{black!10}{\textbullet}]=},
  verbatimenv=doublespace,
}


\begin{document}

\begin{mmaCell}{Input}
\(\Big\{\mmaSup{I}{125},\mmaSup{I}{34},\mmaFrac{1}{\mmaSup{I}{5}},\mmaSup{I}{-15}\Big\}\)
\end{mmaCell}

\begin{mmaCell}{Output}
\(\{\mathsf{i},-1,-\mathsf{i},\mathsf{i}\}\)
\end{mmaCell}

\end{document}

@carlogabrieli
Copy link
Author

carlogabrieli commented Mar 15, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants