-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.tex
112 lines (86 loc) · 2.75 KB
/
example.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
\documentclass{article}
\usepackage{verbatim}
\usepackage{mdframed}
\usepackage{minted}
\renewcommand{\MintedPygmentize}{pygmentize}
\usepackage[utf8]{inputenc}
% LitREPL-compatible environment for code snippets
\newenvironment{python}
{\VerbatimEnvironment
\begin{minted}[breaklines,fontsize=\footnotesize]{python}}
{\end{minted}}
\BeforeBeginEnvironment{python}{
\begin{mdframed}[nobreak=true,frametitle=\tiny{Python}]}
\AfterEndEnvironment{python}{\end{mdframed}}
% LitREPL-compatible environment for code results
\newenvironment{result}{\verbatim}{\endverbatim}
\BeforeBeginEnvironment{result}{
\begin{mdframed}[frametitle=\tiny{Result}]\footnotesize}
\AfterEndEnvironment{result}{\end{mdframed}}
% LitREPL-compatible command for inline code results
\newcommand{\linline}[2]{#2}
\begin{document}
\section{Preamble}
Literpl employs its own internal parser to identify LaTeX-like tags that define
code and result sections. One option is to use the \texttt{python} environment
to mark code and wrap results with \texttt{result}. Both environments need to be
defined in LaTeX so it doesn't get confused. The following preamble sets up both
environments to render as framed boxes of fixed-width text with proper
highlighting:
\begin{verbatim}
\newenvironment{python}
{\VerbatimEnvironment
\begin{minted}[breaklines,fontsize=\footnotesize]{python}}
{\end{minted}}
\BeforeBeginEnvironment{python}{
\begin{mdframed}[nobreak=true,frametitle=\tiny{Python}]}
\AfterEndEnvironment{python}{\end{mdframed}}
\newenvironment{result}{\verbatim}{\endverbatim}
\BeforeBeginEnvironment{result}{
\begin{mdframed}[frametitle=\tiny{Result}]\footnotesize}
\AfterEndEnvironment{result}{\end{mdframed}}
\end{verbatim}
\section{Basic evaluation}
Here is how we can use the environments we just introduced.
\begin{verbatim}
\begin{python}
W='Hello, World!'
print(W)
\end{python}
\end{verbatim}
\begin{python}
W='Hello, World!'
print(W)
\end{python}
\begin{verbatim}
\begin{result}
Hello, World!
\end{result}
\end{verbatim}
\begin{result}
Hello, World!
\end{result}
\section{Producing LaTeX}
Literpl also recognizes \texttt{result} and \texttt{noresult} comments, which
serve as markers for result sections. By using these comments, we can generate
LaTeX markup directly as output.
\begin{verbatim}
\begin{python}
print("\\textbf{Hi!}")
\end{python}
%result
\textbf{Hi!}
%noresult
\end{verbatim}
\begin{python}
print("\\textbf{Hi!}")
\end{python}
%result
\textbf{Hi!}
%noresult
\section{Inline output}
Furthermore, Literpl recognizes \texttt{linline} tags with two arguments. The
first argument is treated as a Python printable expression, while the second
argument will be replaced with its evaluated value.
The value of \texttt{W} happens to be: \linline{W}{Hello, World!}
\end{document}