summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/ydoc/ydoc-expl.sty
blob: 25f45d7ed7db598a2ef800b83bf893d9098dcfab (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
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
%%
%% This is file `ydoc-expl.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ydoc.dtx  (with options: `expl')
%% 
%% Copyright (c) 2010-2011 by Martin Scharrer <martin@scharrer-online.de>
%% WWW: http://latex.scharrer-online.de/
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Martin Scharrer.
%%
%% This work consists of the files ydoc.dtx and ydoc.ins
%% and the derived file ydoc.cls, ydoc.sty, ydoc-code.sty,
%% ydoc-expl.sty and ydoc-desc.sty.
%%
\RequirePackage{svn-prov}[2010/04/03]
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackageSVN
    [ydoc-expl]
    {$Id: ydoc.dtx 2163 2011-02-16 17:19:27Z martin $}
    [v0.4alpha]
    [ydoc package to insert live examples of LaTeX code]
\RequirePackage{listings}
\lst@RequireAspects{writefile}
\def\ydoc@exafile{\jobname.exa}
\def\exampleprintsettings{numbers=left,numberstyle=\tiny\color{gray}\sffamily,numbersep=5pt}%
\newbox\examplecodebox
\newbox\exampleresultbox
\def\BoxExample{%
  \setbox\examplecodebox\hbox{\color@setgroup
    \expandafter\expandafter\expandafter\lstinputlisting
    \expandafter\expandafter\expandafter[%
    \expandafter\exampleprintsettings\expandafter,\thisexampleprintsettings]%
    {\ydoc@exafile}%
  \unskip\color@endgroup}%
  \setbox\exampleresultbox\hbox{\color@setgroup
    \@@input\ydoc@exafile\relax
  \unskip\color@endgroup}%
}
\def\PrintExample{%
  \begingroup
  \BoxExample
  \@tempdima=\textwidth
  \advance\@tempdima by -\wd\examplecodebox\relax
  \advance\@tempdima by -\wd\exampleresultbox\relax
  \advance\@tempdima by -15pt\relax
  \ifdim\@tempdima>\bigskipamount
    \hbox to \textwidth{%
     \null\hss
     \minipage[c]{\wd\exampleresultbox}\fbox{\usebox\exampleresultbox}\endminipage
     \hfill\hfill\hskip\bigskipamount\hskip15pt\hfill\hfill
     \minipage[c]{\wd\examplecodebox}\usebox\examplecodebox\endminipage
     \hss\null
     }%
  \else
    \vbox{%
        \centerline{\fbox{\usebox\exampleresultbox}}%
        \vspace{\bigskipamount}%
        \centerline{\usebox\examplecodebox}%
    }%
  \fi
  \endgroup
}
\def\examplecodesettings{gobble=4}
\lstnewenvironment{examplecode}[1][]{%
  \def\thisexampleprintsettings{#1}%
  \expandafter\lstset\expandafter{\examplecodesettings,#1}%
  \setbox\@tempboxa\hbox\bgroup
  \lst@BeginWriteFile{\ydoc@exafile}%
}
{%
  \lst@EndWriteFile
  \egroup
  \begingroup
  \MakePercentComment
  \catcode`\^^M=5\relax
  \PrintExample
  \endgroup
}
\RequirePackage{float}
\floatstyle{plain}
\newfloat{example}{tbhp}{loe}
\floatname{example}{\examplename}
\def\examplename{Example}
\newenvironment{exampletable}{%
  \floatstyle{plaintop}%
  \restylefloat{example}%
  \example
}{\endexample}
\endinput
%%
%% End of file `ydoc-expl.sty'.