>
>

Mike LaCroix put together a nice latex package that produces In's and Out's
nicely and beautifully but this is unfinished with too much
manual labor required.  Just throwing it out there
figuring someone will improve on it.

Perhaps one should also consider minted -- https://code.google.com/p/minted/
which I know Jiahao Chen likes.

I'll bet someone could make some Julia macros that make this more LaTeX
friendly.

Right now I would  also define something like

\newcommand{\ja}{\begin{jinput}}
\newcommand{\jb}{\end{jinput}\begin{joutput}\begin{verbatim}}
\newcommand{\jc}{\end{verbatim}\end{joutput}}

so the use would be
\ja
\sh {\# Nice Red Comment} \\
Input line 1  \\
Input line 2 \\
Input line 3
\jb
Output lines without slashes
\jc


and on the input lines I would have to put in backslashes before certain
characters, etc.
but it looks nice and automatically numbers

Viral Shah thought that LateX should just execute julia so there is no
human in the loop.
You just type the Julia command input, and the input and output can appear
properly in the document.
\documentclass{article}

\usepackage{graphicx}
\usepackage{color}
\usepackage{framed}

\definecolor{shadecolor}{gray}{.92}
\definecolor{incolor}{rgb}{0,0,.7}
\definecolor{outcolor}{rgb}{.65,0,0}
\definecolor{syntaxcolor}{rgb}{.65,0,0}

\newcommand{\sh}[1]{\textcolor{syntaxcolor}{#1}}

\newcounter{jcounter}
\newenvironment{jinput}[1][]{\ifx#1\relax\else\setcounter{jcounter}{#1}\addtocounter{jcounter}{-1}\fi\refstepcounter{jcounter}\ttfamily\noindent\begin{minipage}[t]{.19\textwidth}\vskip2ex\hspace*{\fill}\textcolor{incolor}{In[\arabic{jcounter}]: }\end{minipage}\begin{minipage}[t]{.8\textwidth}\vskip-0ex\begin{shaded}}{\end{shaded}\end{minipage}\par}
\newenvironment{joutput}[1][]{\vskip1ex plus .2ex minus .1ex\ifx#1\relax\else\setcounter{jcounter}{#1}\fi\addtocounter{jcounter}{-1}\refstepcounter{jcounter}\ttfamily\noindent\begin{minipage}[t]{.19\textwidth}\vskip0ex\hspace*{\fill}\textcolor{outcolor}{Out[\arabic{jcounter}]: }\end{minipage}\begin{minipage}[t]{.8\textwidth}\vskip-0ex}{\end{minipage}\par\vskip1.5ex}

\begin{document}

Normal text, just to make sure vertical spacing is correct.  We can
introduce our makeshift Julia interaction with a paragraph.

\begin{jinput}[8]
f(a::\sh{Any}, b) = \sh{"fallback"}\\
f(a::Number, b::Number) = \sh{"a and b are both numbers"}\\
f(a::Number, b) = \sh{"a is a number"}\\
f(a, b::Number) = \sh{"b is a number"}\\
f(a::Integer, b::Integer) = \sh{"a and b are both integers"}
\end{jinput}
\begin{joutput}
f (generic function with 5 methods)
\end{joutput}
\begin{jinput}
f(1.5,2)
\end{jinput}
\begin{joutput}
"a and b are both numbers"
\end{joutput}
\begin{jinput}\label{jinlabel}
f(1,\sh{"bar"})
\end{jinput}
\begin{joutput}
"a is a number"
\end{joutput}
\begin{jinput}
f(1,2)
\end{jinput}
\begin{joutput}\label{anoutlabel}
"fallback"
\end{joutput}

We can also conclude our interaction with a paragraph.  The numbering
is automatic, with each output matching the previous input.  This can
be updated manually.  We can, for example, refer to
\textcolor{incolor}{In[\ref{jinlabel}]} and \textcolor{outcolor}{Out[\ref{anoutlabel}]}.

\end{document}

Attachment: sourcecode.pdf
Description: Adobe PDF document

Reply via email to