From 1899ca043c36f94224898b8cad0f2cbaf633ab21 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 5 Jan 2014 22:57:58 +0000 Subject: cnltx (5jan14) git-svn-id: svn://tug.org/texlive/trunk@32583 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/cnltx/cnltx-example.sty | 123 +++++++++++++++++---- 1 file changed, 101 insertions(+), 22 deletions(-) (limited to 'Master/texmf-dist/tex/latex/cnltx/cnltx-example.sty') diff --git a/Master/texmf-dist/tex/latex/cnltx/cnltx-example.sty b/Master/texmf-dist/tex/latex/cnltx/cnltx-example.sty index cdc72321c06..ce75c9b1cd0 100644 --- a/Master/texmf-dist/tex/latex/cnltx/cnltx-example.sty +++ b/Master/texmf-dist/tex/latex/cnltx/cnltx-example.sty @@ -8,7 +8,7 @@ % Web: https://github.com/cgnieder/cnltx/ % E-Mail: contact@mychemistry.eu % -------------------------------------------------------------------------- -% Copyright 2013 Clemens Niederberger +% Copyright 2013-2014 Clemens Niederberger % % This work may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either version 1.3 @@ -166,6 +166,7 @@ \newarg\darg{(}{)} \newarg[\code]\Darg{(}{)} \newcommand*\sarg{\textcolor{argument}{\code{*}}} +\newcommand*\parg{\textcolor{argument}{\code{+}}} % -------------------------------------------------------------------------- % source code examples: @@ -278,7 +279,8 @@ % control sequences that won't be indexed: texcsstyle = [6]\color{cs}, index = [6][texcs6], - indexstyle = [6]\@gobble + indexstyle = [6]\@gobble, + moredelim = *[s][\color{math}]{$}{$} } \def\cnltx@bibtex@listings@style{ @@ -402,17 +404,21 @@ } \def\cnltx@local@listings@options{} +\newbool{cnltx@local@sourcecode@overwrite} \pgfkeys{ cnltx/.cd, - gobble/.code = \def\cnltx@gobble{#1} , - add-cmds/.code = \cnltx@addcmds{#1} , - add-silent-cmds/.code = \cnltx@addsilentcmds{#1} , - add-listings-options/.code = \cnltx@addlistingsoptions{#1} , - listings-options/.code = \lstdefinestyle{cnltx}{#1} , - add-envs/.code = \cnltx@addenvs{#1} , - add-silent-envs/.code = \cnltx@addsilentenvs{#1} , - sourcecode-options/.code = \def\cnltx@local@listings@options{#1} , + gobble/.code = \def\cnltx@gobble{#1} , + add-cmds/.code = \cnltx@addcmds{#1} , + add-silent-cmds/.code = \cnltx@addsilentcmds{#1} , + add-listings-options/.code = \cnltx@addlistingsoptions{#1} , + listings-options/.code = \lstdefinestyle{cnltx}{#1} , + add-envs/.code = \cnltx@addenvs{#1} , + add-silent-envs/.code = \cnltx@addsilentenvs{#1} , + add-sourcecode-options/.code = \def\cnltx@local@listings@options{#1} , + sourcecode-options/.code = + \booltrue{cnltx@local@sourcecode@overwrite} + \def\cnltx@local@listings@options{#1} } \def\cnltx@mdframed@options @@ -431,6 +437,9 @@ {\expandonce\cnltx@mdframed@options,\unexpanded{#1}}% } +\def\cnltx@local@frame@options{} +\newbool{cnltx@local@frame@overwrite} + \newbool {cnltx@sidebyside} \newbool {cnltx@codeleft} \booltrue{cnltx@codeleft} @@ -438,6 +447,7 @@ \newbool {cnltx@compile} \newbool {cnltx@float} \newbool {cnltx@pagelist} +\newbool {cnltx@outside}% use this to allow floating material in the examples \newsavebox\cnltx@example@box @@ -480,6 +490,10 @@ after-output/.code = \def\cnltx@after@example@hook{#1} , add-frame-options/.code = \cnltx@addmdframedoptions{#1} , frame-options/.code = \mdfdefinestyle{cnltx}{#1} , + add-local-frame/.code = \def\cnltx@local@frame@options{#1} , + local-frame/.code = + \booltrue{cnltx@local@frame@overwrite} + \def\cnltx@local@frame@options{#1} , gobble/.code = \def\cnltx@gobble{#1} , max-pages/.code = \setcounter{cnltx@maxpages}{#1} , max-height/.code = \def\cnltx@image@max@height{#1} , @@ -506,10 +520,16 @@ } \cnltx@init@float , float/.default = true , + float-env/.code = \def\cnltx@float@type{#1} , caption/.code = \booltrue{cnltx@float}% \renewcommand\cnltx@float@caption{#1} , - float-pos/.code = \def\cnltx@float@pos{[#1]}\cnltx@init@float + float-pos/.code = \def\cnltx@float@pos{[#1]}\cnltx@init@float , + outside/.is if = cnltx@outside , + add-frame/.is choice , + add-frame/true/.code = \def\cnltx@adjustbox@frame{frame} , + add-frame/false/.code = \def\cnltx@adjustbox@frame{} , + add-frame/.default = true } \newcommand*\cnltx@get@page@list[1]{% @@ -608,15 +628,55 @@ \newcommand*\cnltx@example@start[1]{% \pgfqkeys{/cnltx}{#1}% - \cnltx@expandargs(x)\lstset{ - style=cnltx, - \expandonce\cnltx@local@listings@options - }% - \ifbool{cnltx@sidebyside} - {\mdframed[style=cnltx,nobreak=true]} - {\mdframed[style=cnltx,nobreak=false]}% + \ifbool{cnltx@local@sourcecode@overwrite} + {% + \cnltx@expandargs(x)\lstset{ + \expandonce\cnltx@local@listings@options + }% + } + {% + \cnltx@expandargs(x)\lstset{ + style=cnltx, + \expandonce\cnltx@local@listings@options + % no idea why this is necessary: + % \ifcsdef{lst@gtexcs3}{}{,moretexcs=[3]}% + }% + }% + \ifbool{cnltx@local@frame@overwrite} + {% + \cnltx@expandargs(nxx)% + \ifbool{cnltx@sidebyside} + {% + \noexpand\mdframed[ + \expandonce\cnltx@local@frame@options, + nobreak=true] + } + {% + \noexpand\mdframed[ + \expandonce\cnltx@local@frame@options, + nobreak=false] + }% + } + {% + \cnltx@expandargs(nxx)% + \ifbool{cnltx@sidebyside} + {% + \noexpand\mdframed[ + style=cnltx, + \expandonce\cnltx@local@frame@options, + nobreak=true] + } + {% + \noexpand\mdframed[ + style=cnltx, + \expandonce\cnltx@local@frame@options, + nobreak=false] + }% + }% } +\newcommand*\cnltx@adjustbox@frame{frame} + % #1: filename % #2: number of pages % #3: current page @@ -630,7 +690,7 @@ }% \ifblank{#3}{}{% \adjustbox{ - frame, + \cnltx@adjustbox@frame, max width = \cnltx@tmpa@length , max height = \cnltx@image@max@height }{% @@ -677,7 +737,8 @@ \ifboolexpr { bool {cnltx@codeonly} or - bool {cnltx@compile} + bool {cnltx@compile} or + bool {cnltx@outside} } {} {% direct input of code example @@ -753,7 +814,7 @@ } {% \cnltx@example@warning - {`shellescape' or `write18' nor enabled -- I'm not compiling}% + {`shell-escape' or `write18' not enabled -- I'm not compiling}% }% \IfFileExists{#1.\cnltx@example@fileext} {% @@ -808,7 +869,16 @@ } {\endmdframed}% }% - {\endmdframed}% + {% + \endmdframed + \ifbool{cnltx@outside} + {% + \cnltx@pre@example@hook + \cnltx@example@input{#1.code}% + \cnltx@after@example@hook + } + {}% + }% \ignorespacesafterend } @@ -953,5 +1023,14 @@ HISTORY: runs of the included example - new options `program' and `exe-with' - new option `float', `float-pos' and `caption' +2014/01/05 v0.10 - sometimes there is a spurious `undefined control sequence + \lst@gtexcs3' error: added hack to fix this => find out + where this comes from! + - new option `add-frame' for `compile'd examples + - new command \parg for an optional + argument + - new option `outside' for non-`compiled' examples + - new option `float-env' + +TODO: -- cgit v1.2.3