jkuczm / mmacells

Mathematica cells in TeX
61 stars 18 forks source link

Couldn't use the sty. file #20

Closed Zhao-Hang closed 8 years ago

Zhao-Hang commented 8 years ago

Hi, thanks for the fantastic package. I'd really like to give it a try, but when i installed the sty. file (putting it in the same folder as my tex. file), and compile my tex. file, it gave such errors as shown in the figure below. I'm very new to latex/tex. The tex. file is copied from one of your post here.Could you help me with this? Thank you! :) (sorry for reporting this as a new issue) image

jkuczm commented 8 years ago

Few days ago there were some issues with xparse.

Try updating l3kernel and l3packages.

Zhao-Hang commented 8 years ago

Haha, thank you so much! The problem is solved! :+1:

Zhao-Hang commented 8 years ago

Hi, sorry to trouble you again. I have the following code. When i tried to compile the code using Texmaker, it took forever to compile. Do you mind looking into this problem? (Many thanks :)) \begin{mmaCell}[moredefined={d, Ek1, Ek12, Ek2, Ek21, fE1, fE12, fE2, fE21, kB, T, t1, vx12, vy12,\\[Epsilon],\\[Mu],\\[Sigma]w,\\[Sigma]x,\\[Sigma]y,\\[Phi]},morepattern={kx,kx_,ky,ky_}]{Input} \(\phi\)[\{kx_,ky_\}]:=\mmaSqrt{3+2Cos[\mmaSqrt{3}kx]+4Cos[\mmaFrac{\mmaSqrt{3}kx}{2}]Cos[\mmaFrac{3ky}{2}]}; \(\epsilon\)[\{kx_,ky_\}]:=\mmaSqrt{\mmaSup{d}{2}+\mmaSup{\(\phi\)[\{kx,ky\}]}{2}}; Ek1[\{kx_,ky_\}]:=t1 (\mmaSup{\(\phi\)[\{kx,ky\}]}{2}-3)+\(\epsilon\)[\{kx,ky\}]; Ek2[\{kx_,ky_\}]:=t1 (\mmaSup{\(\phi\)[\{kx,ky\}]}{2}-3)-\(\epsilon\)[\{kx,ky\}]; Ek12[\{kx_,ky_\}]:=Ek1[\{kx,ky\}]-Ek2[\{kx,ky\}]; Ek21[\{kx_,ky_\}]:=Ek2[\{kx,ky\}]-Ek1[\{kx,ky\}]; fE1[\{kx_,ky_\}]:=\mmaFrac{1}{Exp[\mmaFrac{Ek1[\{k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]}{2}}; \end{mmaCell}

jkuczm commented 8 years ago

Problem is that some arguments of some formatting commands are processed in math mode, so using \( \) inside them leads to errors. It was done to allow LaTeXs special formatting of subscripts and superscripts of things like \int or \sum.

Try following code instead:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=2cm]{geometry}

\usepackage{mmacells}

\begin{document}

\mmaDefineMathReplacement{ϕ}{\phi}
\mmaDefineMathReplacement{ε}{\epsilon}
\mmaDefineMathReplacement{σ}{\sigma}

\begin{mmaCell}[
  moredefined={d, Ek1, Ek12, Ek2, Ek21, fE1, fE12, fE2, fE21, kB, T, t1, vx12, vy12},
  morepattern={kx,kx_,ky,ky_}
]{Input}
ϕ[\{kx_,ky_\}]:=\mmaSqrt{3+2Cos[\mmaSqrt{3}kx]+4Cos[\mmaFrac{\mmaSqrt{3}kx}{2}]Cos[\mmaFrac{3ky}{2}]};
ε[\{kx_,ky_\}]:=\mmaSqrt{\mmaSup{d}{2}+\mmaSup{ϕ[\{kx,ky\}]}{2}};
Ek1[\{kx_,ky_\}]:=t1 (\mmaSup{ϕ[\{kx,ky\}]}{2}-3)+ε[\{kx,ky\}];
Ek2[\{kx_,ky_\}]:=t1 (\mmaSup{ϕ[\{kx,ky\}]}{2}-3)-ε[\{kx,ky\}];
Ek12[\{kx_,ky_\}]:=Ek1[\{kx,ky\}]-Ek2[\{kx,ky\}];
Ek21[\{kx_,ky_\}]:=Ek2[\{kx,ky\}]-Ek1[\{kx,ky\}];
vx12[\{kx_,ky_\}]:=
    -\mmaFrac{\mmaSqrt{3} Sin[\mmaFrac{\mmaSqrt{3} kx}{2}] (2d Cos[\mmaFrac{\mmaSqrt{3} kx}{2}]+d Cos[\mmaFrac{3 ky}{2}]+i ε[\{kx,ky\}] Sin[\mmaFrac{3 ky}{2}])}{ε[\{kx,ky\}] ϕ[\{kx,ky\}]};
vy12[\{kx_,ky_\}]:=
    \mmaFrac{i (ε[\{kx,ky\}] Cos[\mmaSqrt{3} kx]+Cos[\mmaFrac{\mmaSqrt{3} kx}{2}](3 i d Sin[\mmaFrac{3 ky}{2}]-ε[\{kx,ky\}] Cos[\mmaFrac{3 \ ky}{2}]))}{ε[\{kx,ky\}] ϕ[\{kx,ky\}]};
\mmaDef{σx}[\{kx_,ky_\}]:=\mmaFrac{\mmaSup{Abs[vx12[\{kx,ky\}]]}{2} fE21[\{kx,ky\}]}{Ek12[\{kx,ky\}]};
\mmaDef{σy}[\{kx_,ky_\}]:=\mmaFrac{\mmaSup{Abs[vy12[\{kx,ky\}]]}{2} fE21[\{kx,ky\}]}{Ek12[\{kx,ky\}]};
\mmaDef{σw}[\{kx_,ky_\}]:=
    -\mmaFrac{(fE21[\{kx,ky\}]\mmaSup{Abs[vy12[\{kx,ky\}]]}{2}) d (Cos[\mmaSqrt{3} kx]-Cos[\mmaFrac{\mmaSqrt{3}kx}{2}]Cos[\mmaFrac{3ky}{2}])}{ε[\{kx,ky\}] \mmaSup{ϕ[\{kx,ky\}]}{2} \mmaSup{Ek12[\{kx,ky\}]}{2}};
\end{mmaCell}

\end{document}

Which gives following pdf: screen1

I guess your original TeX code was generated by CellsToTeX package, which reveals a bug in that package, in treatment of symbols containing non-ASCII characters.

Nithilher commented 8 years ago

I have a similar problem, that a few lines of code generated be the CellsToTex package makes pdflatex choke and take for ever. Here the output of my call to CellsToTex which, when inserted into my LaTeX document, cannot be compiled in finite time:

\begin{mmaCell}[morepattern={z, z_},moredefined={ρ}]{Input}
  \(\rho\)[z_] := \mmaSub{\rho}{0} z Exp[-\(\lambda\) Abs[z]]
\end{mmaCell}

\begin{mmaCell}[moredefined={Ez, ρ},morepattern={z, z_}]{Input}
  Ez[z_] := - \mmaSub{\rho}{0}/\mmaSub{\epsilon}{0} (1+\(\lambda\) \
Abs[z])/\(\lambda\)^2 Exp[-\(\lambda\) Abs[z]] 
\end{mmaCell}

\begin{mmaCell}[moredefined={Ez, \
Φ},morefunctionlocal={x},morepattern={z_}]{Input}
  \(\Phi\)[z_] = -Integrate[Ez[x],\{x,0,z\}]
\end{mmaCell}

\begin{mmaCell}{Output}
  -\mmaFrac{\mmaSup{e}{-\mmaFrac{z \(\lambda\)}{Sign[z]}} (z \
\(\lambda\)-2 (-1+\mmaSup{e}{\mmaFrac{z \(\lambda\)}{Sign[z]}}) \
Sign[z]) \mmaSub{\rho}{0}}{\mmaSup{\lambda}{3}
\mmaSub{\epsilon}{0}}
\end{mmaCell}

As far as I can see it looks very innocent. I am not sure what the unicode characters in the moredefined={...} entries mean, and where they come from. I should add that all I did was to include \usepackcage[mmacells] Should I have used some further initializing commands?

jkuczm commented 8 years ago

@Nithilher the cause of pdflatex choking is explicit newline in last cell, between \mmaSup{\lambda}{3} and \mmaSub{\epsilon}{0}, it shouldn't be used inside formatting command like \mmaFrac.

Could you post cell expression (ctrl+shift+E with cursor somewhere inside cell) of this Output cell and code you used to generate TeX code?

The fact that non-ASCII characters appear in moredefined option is a bug in CellsToTeX package, that I hope to fix in near future. Since listings can't handle Unicode properly, all symbol names containing non-ASCII should be dealt with using explicit annotations and not using environments options.

The code for your case can be something like following:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=2cm]{geometry}

\usepackage{mmacells}

\begin{document}

\mmaSet{morefv={gobble=2}}

\mmaDefineMathReplacement{ρ}{\rho}
\mmaDefineMathReplacement{λ}{\lambda}
\mmaDefineMathReplacement{Φ}{\Phi}
\mmaDefineMathReplacement{ε}{\epsilon}

\begin{mmaCell}[morepattern={z, z_}]{Input}
  \mmaDef{ρ}[z_] := \mmaSub{ρ}{0} z Exp[-\mmaUnd{λ} Abs[z]]
\end{mmaCell}

\begin{mmaCell}[moredefined={Ez},morepattern={z, z_}]{Input}
  Ez[z_] := - \mmaSub{\mmaDef{ρ}}{0}/\mmaSub{\mmaUnd{ε}}{0} (1+\mmaUnd{λ}\
Abs[z])/\mmaUnd{λ}^2 Exp[-\mmaUnd{λ} Abs[z]] 
\end{mmaCell}

\begin{mmaCell}[moredefined={Ez},morefunctionlocal={x},morepattern={z_}]{Input}
  \mmaDef{Φ}[z_] = -Integrate[Ez[x],\{x,0,z\}]
\end{mmaCell}

\begin{mmaCell}{Output}
  -\mmaFrac{\mmaSup{e}{-\mmaFrac{z λ}{Sign[z]}} (z\
λ-2 (-1+\mmaSup{e}{\mmaFrac{z λ}{Sign[z]}})\
Sign[z]) \mmaSub{ρ}{0}}{\mmaSup{λ}{3}\mmaSub{ε}{0}}
\end{mmaCell}

\end{document}
Nithilher commented 8 years ago

Dear Jakub,

many thanks, that worked beautifully. I will post the information you wish a bit later, I don't have access to my mathematica machine at the moment.

I have one small request. I would like to set the Input Code of mathematica in borderless boxes of full width (\ŧextwidth) with a light gray as background color. However, when putting your code within \colorbox{bg}{...}, I get an error:

\definecolor{bg}{rgb}{0.95,0.95,0.95} \colorbox{bg}{% \begin{mmaCell}[morepattern={z, z}]{Input} \mmaDef{ρ}[z] := \mmaSub{ρ}{0} z Exp[-\mmaUnd{λ} Abs[z]] \end{mmaCell} }

yields

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ...

Is there a simple way to achive this?

Best regards, Michael

On 21/04/16 22:02, Jakub Kuczmarski wrote:

@Nithilher https://github.com/Nithilher the cause of |pdflatex| choking is explicit newline in last cell, between |\mmaSup{\lambda}{3}| and |\mmaSub{\epsilon}{0}|.

Could you post cell expression (|ctrl|+|shift|+|E| with cursor somewhere inside cell) of this Output cell and code you used to generate TeX code?

The fact that non-ASCII characters appear in |moredefined| option is a bug in |CellToTeX| package, that I hope to fix in near future. Since |listings| can't handle Unicode properly, all symbol names containing non-ASCII should be dealt with using explicit annotations and not using environments options.

The code for your case can be something like following:

\documentclass{article}

\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage[margin=2cm]{geometry}

\usepackage{mmacells}

\begin{document}

\mmaSet{morefv={gobble=2}}

\mmaDefineMathReplacement{ρ}{\rho} \mmaDefineMathReplacement{λ}{\lambda} \mmaDefineMathReplacement{Φ}{\Phi} \mmaDefineMathReplacement{ε}{\epsilon}

\begin{mmaCell}[morepattern={z, z}]{Input} \mmaDef{ρ}[z] := \mmaSub{ρ}{0} z Exp[-\mmaUnd{λ} Abs[z]] \end{mmaCell}

\begin{mmaCell}[moredefined={Ez},morepattern={z, z}]{Input} Ez[z] := - \mmaSub{\mmaDef{ρ}}{0}/\mmaSub{\mmaUnd{ε}}{0} (1+\mmaUnd{λ}\ Abs[z])/\mmaUnd{λ}^2 Exp[-\mmaUnd{λ} Abs[z]] \end{mmaCell}

\begin{mmaCell}[moredefined={Ez},morefunctionlocal={x},morepattern={z}]{Input} \mmaDef{Φ}[z] = -Integrate[Ez[x],{x,0,z}] \end{mmaCell}

\begin{mmaCell}{Output} -\mmaFrac{\mmaSup{e}{-\mmaFrac{z λ}{Sign[z]}} (z\ λ-2 (-1+\mmaSup{e}{\mmaFrac{z λ}{Sign[z]}})\ Sign[z]) \mmaSub{ρ}{0}}{\mmaSup{λ}{3}\mmaSub{ε}{0}} \end{mmaCell}

\end{document}

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/jkuczm/mmacells/issues/20#issuecomment-213092361

P D D r M i c h a e l F l o h r .. www.michael-flohr.de Institute for Theoretical Physics .: +49.511.762.3656 (T) Leibniz University Hannover :. +49.511.762.3023 (F) Appelstrasse 2 .. D-30167 Hannover :: hbar@michael-flohr.de

jkuczm commented 8 years ago

@Nithilher let's move \colorbox problem to separate issue: #21.

jkuczm commented 8 years ago

Since mmacells v0.3.0 formatting commands process all arguments in text mode so problem raised by @Zhao-Hang should be solved.

jkuczm commented 8 years ago

Bug of CellsToTeX package, reported by @Nithilher, that caused appearance of non-ASCII characters in mmaCell environment options is fixed in CellsToTeX v0.2.0