summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/xsim/examples/xsim.code-and-output.tex
blob: 15b1a7dea009d9fce768906998571fea7cc7941e (plain)
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
\documentclass{article}
\usepackage{xsimverb,listings,xcolor}

\lstdefinestyle{mystyle}{
  language = [AlLaTeX]TeX ,
  basicstyle = \ttfamily ,
  columns = fullflexible ,
  commentstyle = \color{gray!70} ,
  keywordstyle = \color{red!70!black}
}

\makeatletter
\NewDocumentEnvironment{example}{!o}
  {%
    \XSIMgobblechars{2}%
    \XSIMsetfilebegin{\@percentchar\space file `\jobname.tmp'}%
    \XSIMsetfileend{\@percentchar\space bye bye}%
    \IfNoValueTF{#1}
      {\XSIMfilewritestart*{\jobname.tmp}}
      {\XSIMfilewritestart{\jobname.tmp}}%
  }
  {%
    \XSIMfilewritestop
    \lstinputlisting[style=mystyle]{\jobname.tmp}%
    \input{\jobname.tmp}
  }

\NewDocumentEnvironment{code}{!o}
  {%
    \XSIMgobblechars{2}%
    \IfNoValueTF{#1}
      {\XSIMfilewritestart*{\jobname.tmp}}
      {\XSIMfilewritestart{\jobname.tmp}}%
  }
  {%
    \XSIMfilewritestop
    \lstinputlisting[style=mystyle]{\jobname.tmp}%
  }
\makeatother

\begin{document}

\begin{example}
  bla bla \LaTeX
\end{example}

\bigskip

\begin{code}
  blubber \LaTeX
\end{code}

\end{document}