diff options
author | Karl Berry <karl@freefriends.org> | 2015-01-11 22:25:35 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2015-01-11 22:25:35 +0000 |
commit | ffd0a5d337e9ff3c89109f208771ec70f599ebef (patch) | |
tree | 1dfea0d60d89adbe1b9489c034939d9112ba8cb0 /Master/texmf-dist/tex/latex/cnltx/cnltx-example.sty | |
parent | ffc578485f0573fbef95749a3b239380be42da87 (diff) |
cnltx (11jan15)
git-svn-id: svn://tug.org/texlive/trunk@36025 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/cnltx/cnltx-example.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/cnltx/cnltx-example.sty | 170 |
1 files changed, 89 insertions, 81 deletions
diff --git a/Master/texmf-dist/tex/latex/cnltx/cnltx-example.sty b/Master/texmf-dist/tex/latex/cnltx/cnltx-example.sty index ce75c9b1cd0..256e154fb15 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-2014 Clemens Niederberger +% Copyright 2013-2015 Clemens Niederberger % % This work may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either version 1.3 @@ -27,7 +27,7 @@ % -------------------------------------------------------------------------- \RequirePackage{cnltx-base} \ProvidesPackage{cnltx-example}[\cnltx@@date\space \cnltx@@version\space \cnltx@@info] -\RequirePackage{cnltx-listings} +\cnltx@load@modules{listings,translations} \cnltx@create@bundle@message{example}{Error} \cnltx@create@bundle@message{example}{Warning} @@ -35,10 +35,10 @@ \cnltx@create@bundle@message{example}{Info} % -------------------------------------------------------------------------- -\RequirePackage{translations} \PassOptionsToPackage{framemethod=tikz}{mdframed} \RequirePackage{mdframed} \RequirePackage{idxcmds} +\RequirePackage{textcomp} \RequirePackage{adjustbox} \RequirePackage{ifxetex} @@ -58,7 +58,7 @@ \newidxcmd\cs{\code{\textbackslash\textcolor{cs}{#1}}} % \env -\newidxcmd\env{\code{#1}}[\ (\GetTranslation{cnltx-environment})] +\newidxcmd\env{\code{\textcolor{env}{#1}}}[\ (\GetTranslation{cnltx-environment})] % \begin, \end \newidxcmd\beginend{\code{\textbackslash\textcolor{beginend}{#1}}} @@ -207,7 +207,7 @@ } \lst@RequireAspects{writefile} -\providecommand*\MakePercentComment{\catcode`\%14\relax} +\providecommand*\MakePercentComment{\cnltx@set@catcode{\%}{14}} \def\cnltx@gobble{2} @@ -229,7 +229,9 @@ {Ä}{{\"A}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1 - {ß}{{\ss}}1 , + {ß}{{\ss}}1 + {`}{\`{}}1 + {'}{\textquotesingle}1 , breaklines = true, keepspaces = true, breakindent = 1em, @@ -242,6 +244,7 @@ center, description,document, end,enumerate, + equation,eqnarray, figure,flushleft,flushright, itemize,list, otherlanguage, @@ -254,6 +257,7 @@ center, description,document, end,enumerate, + equation,eqnarray, figure,flushleft,flushright, itemize,list, otherlanguage, @@ -264,20 +268,20 @@ index = [2][texcs2], indexstyle = [2]\@gobble, moretexcs = [2]{begin,end}, - % added environments that'll be indexed: - texcsstyle = [3]\color{env}, + % control sequences that'll be indexed: + texcsstyle = [3]\color{cs}, index = [3][texcs3], - indexstyle = [3]\indexenv, - % environments that won't be indexed: - texcsstyle = [4]\color{env}, + indexstyle = [3]\indexcs, + % control sequences that won't be indexed: + texcsstyle = [4]\color{cs}, index = [4][texcs4], indexstyle = [4]\@gobble, - % control sequences that'll be indexed: - texcsstyle = [5]\color{cs}, + % added environments that'll be indexed: + texcsstyle = [5]\color{env}, index = [5][texcs5], - indexstyle = [5]\indexcs, - % control sequences that won't be indexed: - texcsstyle = [6]\color{cs}, + indexstyle = [5]\indexenv, + % environments that won't be indexed: + texcsstyle = [6]\color{env}, index = [6][texcs6], indexstyle = [6]\@gobble, moredelim = *[s][\color{math}]{$}{$} @@ -357,18 +361,18 @@ \def\cnltx@addcmds#1{% \cnltx@expandargs(nx)\lstdefinestyle {cnltx} - {\expandonce\cnltx@listings@style,\unexpanded{moretexcs={[5]#1}}}% + {\expandonce\cnltx@listings@style,\unexpanded{moretexcs={[3]#1}}}% \edef\cnltx@listings@style{% - \expandonce\cnltx@listings@style,\unexpanded{moretexcs={[5]#1}}% + \expandonce\cnltx@listings@style,\unexpanded{moretexcs={[3]#1}}% }% } \def\cnltx@addsilentcmds#1{% \cnltx@expandargs(nx)\lstdefinestyle {cnltx} - {\expandonce\cnltx@listings@style,\unexpanded{moretexcs={[6]#1}}}% + {\expandonce\cnltx@listings@style,\unexpanded{moretexcs={[4]#1}}}% \edef\cnltx@listings@style{% - \expandonce\cnltx@listings@style,\unexpanded{moretexcs={[6]#1}}% + \expandonce\cnltx@listings@style,\unexpanded{moretexcs={[4]#1}}% }% } @@ -377,18 +381,18 @@ \def\cnltx@addenvs#1{% \cnltx@expandargs(nx)\lstdefinestyle {cnltx} - {\expandonce\cnltx@listings@style,\unexpanded{moretexcs={[3]#1}}}% + {\expandonce\cnltx@listings@style,\unexpanded{moretexcs={[5]#1}}}% \edef\cnltx@listings@style{% - \expandonce\cnltx@listings@style,\unexpanded{moretexcs={[3]#1}}% + \expandonce\cnltx@listings@style,\unexpanded{moretexcs={[5]#1}}% }% } \def\cnltx@addsilentenvs#1{% \cnltx@expandargs(nx)\lstdefinestyle {cnltx} - {\expandonce\cnltx@listings@style,\unexpanded{moretexcs={[4]#1}}}% + {\expandonce\cnltx@listings@style,\unexpanded{moretexcs={[6]#1}}}% \edef\cnltx@listings@style{% - \expandonce\cnltx@listings@style,\unexpanded{moretexcs={[4]#1}}% + \expandonce\cnltx@listings@style,\unexpanded{moretexcs={[6]#1}}% }% } @@ -415,17 +419,20 @@ 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} , + add-sourcecode-options/.code = + \edef\cnltx@local@listings@options{\trim@spaces@noexp{#1}} , sourcecode-options/.code = \booltrue{cnltx@local@sourcecode@overwrite} - \def\cnltx@local@listings@options{#1} + \edef\cnltx@local@listings@options{\trim@spaces@noexp{#1}} } \def\cnltx@mdframed@options { backgroundcolor = cnltxbg , linecolor = cnltx , - roundcorner = 5pt + roundcorner = 5pt , + skipabove = .5\baselineskip , + skipbelow = .5\baselineskip } \cnltx@expandargs(nx)\mdfdefinestyle {cnltx} @@ -451,6 +458,10 @@ \newsavebox\cnltx@example@box +\newlength\cnltx@sidebysidewidth +\newlength\cnltx@before@skip +\newlength\cnltx@after@skip + \newcommand*\cnltx@examplesep{\hrulefill} \newcommand*\cnltx@pre@source@hook{} \newcommand*\cnltx@after@source@hook{} @@ -529,9 +540,14 @@ 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 + add-frame/.default = true , + before-skip/.code = \setlength\cnltx@before@skip{#1} , + after-skip/.code = \setlength\cnltx@after@skip{#1} } +\setlength\cnltx@before@skip{\baselineskip} +\setlength\cnltx@after@skip{\baselineskip} + \newcommand*\cnltx@get@page@list[1]{% \forcsvlist{\cnltx@read@page@list@item}{#1}% } @@ -614,29 +630,43 @@ \endgroup } -\newcommand*\cnltx@source@input@start[1]{% +\newrobustcmd*\cnltx@source@input@start[1]{% \ifboolexpr{ bool {cnltx@sidebyside} and not bool {cnltx@codeonly} } - {\setbox\cnltx@example@box=\hbox\bgroup}{\cnltx@pre@source@hook}% - \lst@BeginAlsoWriteFile{#1}% + {% + \adjustbox{ + % discard, + trim= 0pt 0pt \linewidth{} 0pt, + valign=c, + gstore=\cnltx@example@box, + discard + }\bgroup + } + {\cnltx@pre@source@hook}% + \lst@BeginAlsoWriteFile{#1}% } -\newcommand*\cnltx@source@input@end{% +\newrobustcmd*\cnltx@source@input@end{% \lst@EndWriteFile \ifboolexpr{ bool {cnltx@sidebyside} and not bool {cnltx@codeonly} } {\egroup}{\cnltx@after@source@hook}% } -\newcommand*\cnltx@example@start[1]{% +\newrobustcmd*\cnltx@example@start[1]{% \pgfqkeys{/cnltx}{#1}% \ifbool{cnltx@local@sourcecode@overwrite} {% \cnltx@expandargs(x)\lstset{ + \ifboolexpe{ bool {cnltx@sidebyside} and not bool {cnltx@codeonly} } + {linewidth=\cnltx@sidebysidewidth,}{}% + moretexcs=[3], moretexcs=[5], \expandonce\cnltx@local@listings@options }% } {% \cnltx@expandargs(x)\lstset{ style=cnltx, + \ifboolexpe{ bool {cnltx@sidebyside} and not bool {cnltx@codeonly} } + {linewidth=\cnltx@sidebysidewidth,}{}% \expandonce\cnltx@local@listings@options % no idea why this is necessary: % \ifcsdef{lst@gtexcs3}{}{,moretexcs=[3]}% @@ -645,7 +675,7 @@ \ifbool{cnltx@local@frame@overwrite} {% \cnltx@expandargs(nxx)% - \ifbool{cnltx@sidebyside} + \ifboolexpe{ bool {cnltx@sidebyside} and not bool {cnltx@codeonly} } {% \noexpand\mdframed[ \expandonce\cnltx@local@frame@options, @@ -659,7 +689,7 @@ } {% \cnltx@expandargs(nxx)% - \ifbool{cnltx@sidebyside} + \ifboolexpe{ bool {cnltx@sidebyside} and not bool {cnltx@codeonly} } {% \noexpand\mdframed[ style=cnltx, @@ -680,7 +710,7 @@ % #1: filename % #2: number of pages % #3: current page -\newcommand*\cnltx@print@documentpage[3]{% +\newrobustcmd*\cnltx@print@documentpage[3]{% \cnltx@expandargs(x)\setlength\cnltx@tmpa@length{% \strip@pt\dimexpr1pt/% \ifnumgreater{#2}{\value{cnltx@maxpages}} @@ -728,11 +758,11 @@ }% } -\newcommand*\cnltx@stepcounter@ifnotempty[2]{% +\newrobustcmd*\cnltx@stepcounter@ifnotempty[2]{% \ifblank{#2}{}{\stepcounter{#1}}% } -\newcommand*\cnltx@example@end[1]{% +\newrobustcmd*\cnltx@example@end[1]{% \ifblank{#1}{\booltrue{cnltx@codeonly}}{} \ifboolexpr { @@ -742,48 +772,32 @@ } {} {% direct input of code example + % \showthe\wd\cnltx@example@box + % \showthe\linewidth \ifbool{cnltx@sidebyside} {% side-by-side \ifbool{cnltx@codeleft} {% code on the left - \minipage[c]{% - \dimexpr - .49\linewidth - -.75\lst@xleftmargin - \relax - }% + \noindent + \minipage[c]{\cnltx@sidebysidewidth}% \cnltx@pre@source@hook \unhbox\cnltx@example@box \cnltx@after@source@hook \endminipage\hfill - \minipage[c]{% - \dimexpr - .49\linewidth - -.75\lst@xleftmargin - \relax - }% + \minipage[c]{\cnltx@sidebysidewidth}% \cnltx@pre@example@hook \cnltx@example@input{#1.code}% \cnltx@after@example@hook \endminipage } {% code on the right - \minipage[c]{% - \dimexpr - .49\linewidth - -.75\lst@xleftmargin - \relax - }% + \noindent + \minipage[c]{\cnltx@sidebysidewidth}% \cnltx@pre@example@hook \cnltx@example@input{#1.code}% \cnltx@after@example@hook \endminipage\hfill - \minipage[c]{% - \dimexpr - .49\linewidth - -.75\lst@xleftmargin - \relax - }% + \minipage[c]{\cnltx@sidebysidewidth}% \cnltx@pre@source@hook \unhbox\cnltx@example@box \cnltx@after@source@hook @@ -865,12 +879,13 @@ {% \cnltx@after@example@hook \endmdframed + \par }% } - {\endmdframed}% + {\endmdframed\par}% }% {% - \endmdframed + \endmdframed\par \ifbool{cnltx@outside} {% \cnltx@pre@example@hook @@ -885,6 +900,12 @@ \def\cnltx@new@sourcecode@env#1#2{% \lstnewenvironment{#2}[1][] {% + \vskip\cnltx@before@skip + \setlength\cnltx@sidebysidewidth + {\dimexpr .45\columnwidth -\lst@xleftmargin -\lst@xrightmargin\relax}% + \ifboolexpr{ bool {cnltx@sidebyside} and not bool {cnltx@codeonly} } + {\cnltx@addlistingsoptions{linewidth=\cnltx@sidebysidewidth}} + {}% \cnltx@example@start{##1,#1}% \ifbool{cnltx@compile}{% \stepcounter{cnltx@filenumber}% @@ -901,6 +922,8 @@ \if@nobreak \@nobreakfalse \fi + \csname par\endcsname + \vskip\cnltx@after@skip }% } \newrobustcmd\newsourcecodeenv[2][]{% @@ -967,22 +990,6 @@ }% } -\DeclareTranslationFallback{cnltx-package}{package} -\DeclareTranslation{English}{cnltx-package}{package} -\DeclareTranslation{German}{cnltx-package}{Paket} - -\DeclareTranslationFallback{cnltx-environment}{environment} -\DeclareTranslation{English}{cnltx-environment}{environment} -\DeclareTranslation{German}{cnltx-environment}{Umgebung} - -\DeclareTranslationFallback{cnltx-class}{class} -\DeclareTranslation{English}{cnltx-class}{class} -\DeclareTranslation{German}{cnltx-class}{Klasse} - -\DeclareTranslationFallback{cnltx-bundle}{bundle} -\DeclareTranslation{English}{cnltx-bundle}{bundle} -\DeclareTranslation{German}{cnltx-bundle}{Bundle} - \endinput % -------------------------------------------------------------------------- @@ -1030,7 +1037,8 @@ HISTORY: - new command \parg for an optional + argument - new option `outside' for non-`compiled' examples - new option `float-env' - +2014/03/11 v0.11 - \cnltx@load@modules +2014/04/09 v0.12 - improvements on the sidebyside examples TODO: |