jkuczm / mmacells

Mathematica cells in TeX
61 stars 18 forks source link

Adding Caption #38

Closed abduld closed 5 years ago

abduld commented 5 years ago

Is there a way to add a caption using this package. I am trying this code

\begin{mmaCell}[
  label=,
  linkbuiltin=List,
  pattern={fun, arg, c, len},
  moredefined={RandomReal},
  caption={My Caption}
]{Input}
fun = Function[{len}, 
    NestList[
      Function[{c},
        Module[{arg = RandomReal[{0., 2. Pi}]},
          {Sin[arg], Cos[arg]}
        ] + c
    ],
    {0., 0.},
    len
]];
\end{mmaCell}
jkuczm commented 5 years ago

mmaCell is based on fancyvrbs Verbatim environment. You can use morefv key to pass options directly to Verbatim environment. Verbatim offers simple captions with its label option (see section 4.1.7 of fancyvrb documentation).

Note also that Input cell style allows formatting commands, which means that { and } characters need to be escaped. Since above cell is not using any formatting commands, you might be better served by Code cell style.

linkbuiltin works only for identifiers that appear verbatim in a cell. While there are Lists in your code, List identifier doesn't appear there, so linkbuiltin=List option is not used. It would work for identifiers that do appear like NestList.

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

\begin{document}

\begin{mmaCell}[
  label=,
  linkbuiltin=NestList,
  pattern={fun, arg, c, len},
  moredefined={RandomReal},
  morefv={frame=topline,framerule=0pt,framesep=1em,label=\textnormal{My Caption}}
]{Code}
fun = Function[{len}, 
    NestList[
      Function[{c},
        Module[{arg = RandomReal[{0., 2. Pi}]},
          {Sin[arg], Cos[arg]}
        ] + c
    ],
    {0., 0.},
    len
]];
\end{mmaCell}

\end{document}

PDF output

abduld commented 5 years ago

great. thanks