From 4f243e567cce42bca2f019edec58026baf5b6162 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 21 Mar 2011 21:59:45 +0000 Subject: ydoc (21mar11) git-svn-id: svn://tug.org/texlive/trunk@21787 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/ydoc/ydoc-desc.sty | 380 +++++++++++++++++-------- 1 file changed, 264 insertions(+), 116 deletions(-) (limited to 'Master/texmf-dist/tex/latex/ydoc/ydoc-desc.sty') diff --git a/Master/texmf-dist/tex/latex/ydoc/ydoc-desc.sty b/Master/texmf-dist/tex/latex/ydoc/ydoc-desc.sty index 43d9be9330c..a9e69681788 100644 --- a/Master/texmf-dist/tex/latex/ydoc/ydoc-desc.sty +++ b/Master/texmf-dist/tex/latex/ydoc/ydoc-desc.sty @@ -6,6 +6,7 @@ %% %% ydoc.dtx (with options: `desc') %% +%% %% Copyright (c) 2010-2011 by Martin Scharrer %% WWW: http://latex.scharrer-online.de/ %% @@ -25,76 +26,122 @@ %% 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-desc] - {$Id: ydoc.dtx 2163 2011-02-16 17:19:27Z martin $} - [v0.4alpha] +\RequirePackage{svn-prov}[2010/04/03] +\ProvidesPackageSVN[ydoc-desc] + {$Id: ydoc_desc_sty.dtx 2369 2011-03-20 00:04:45Z martin $} + [v0.5alpha] [ydoc package to describe macros, environments, options etc.] -\RequirePackage{hyperref} -\hypersetup{colorlinks=true,pdfborder=0 0 0,pdfborderstyle={}} +\IfFileExists{needspace.sty}{% + \RequirePackage{needspace} +}{% + \def\Needspace{\@ifstar\@gobble\@gobble} +} \RequirePackage{shortvrb} +\RequirePackage{etoolbox} \RequirePackage{xcolor} -\definecolor{macrodesc}{rgb}{0.0,0.0,0.8} -\definecolor{macroimpl}{rgb}{0.0,0.0,0.4} -\definecolor{meta}{rgb}{0.0,0.4,0.4} +\definecolor{macrodesc}{rgb}{0,0.2,0.6} +\definecolor{macroimpl}{rgb}{0,0.1,0.3} +\definecolor{meta}{rgb}{0,0.25,0.75} \definecolor{scriptcolor}{rgb}{0.2,0.6,0.2} \definecolor{optioncolor}{rgb}{0.3.0.2,0} \colorlet{optional}{black!65!white} \colorlet{metaoptional}{optional!50!meta} -\def\meta#1{% +\providecolor{urlcolor}{named}{blue} +\providecolor{linkcolor}{named}{blue} +\providecolor{filecolor}{named}{blue} +\providecolor{citecolor}{named}{blue} +\providecolor{anchorcolor}{named}{blue} +\providecolor{menucolor}{named}{blue} +\providecolor{runcolor}{named}{blue} + +\RequirePackage{hyperref} +\hypersetup{% + colorlinks=true, + pdfborder=0 0 0, + pdfborderstyle={}, + urlcolor=urlcolor, + linkcolor=linkcolor, + filecolor=filecolor, + citecolor=citecolor, + anchorcolor=anchorcolor, + menucolor=menucolor, + runcolor=runcolor, +} + +\newrobustcmd*\meta[1]{% + {\metastyle{% \ensuremath\langle - {\metastyle{#1\/}}% + #1\/% \ensuremath\rangle + }}% } -\def\marg#1{\@marg{<#1>}} -\def\oarg#1{\@oarg{<#1>}} -\def\parg#1{\@parg{<#1>}} -\def\aarg#1{\@aarg{<#1>}} -\def\@marg#1{% +\newrobustcmd*{\marg}[1]{% {\margstyle{% {\ttfamily\braceleft}% - {\def\end@Macro@args{}\read@Macro@arg#1}% + \meta{#1}% {\ttfamily\braceright}% }}% } -\def\@oarg#1{% +\newrobustcmd*{\oarg}[1]{% {\oargstyle{% {\ttfamily[}% - {\def\end@Macro@args{}\read@Macro@arg#1}% + \meta{#1}% {\ttfamily]}% }}% } -\def\@parg#1{% +\newrobustcmd*{\parg}[1]{% {\pargstyle{% {\ttfamily(}% - {\def\end@Macro@args{}\read@Macro@arg#1}% + \meta{#1}% {\ttfamily)}% }}% } -\def\@aarg#1{% +\newrobustcmd*{\aarg}[1]{% {\aargstyle{% {\ttfamily<}% - {\def\end@Macro@args{}\read@Macro@arg#1}% + \meta{#1}% {\ttfamily>}% }}% } -\def\sarg{{\sargstyle{*}}} -\RequirePackage{etoolbox} -\newrobustcmd*\pkg{\texttt} -\newrobustcmd*\cls{\texttt} -\newrobustcmd*\env{\texttt} -\newrobustcmd*\opt{\textsf} +\newrobustcmd*{\sarg}{{\sargstyle{*}}} +\newrobustcmd*\pkg[1]{{\pkgstyle{#1}}} +\newrobustcmd*\cls[1]{{\clsstyle{#1}}} +\newrobustcmd*\lib[1]{{\libstyle{#1}}} +\newrobustcmd*\env[1]{{\envstyle{#1}}} + +\newrobustcmd*\opt{\@ifstar\ys@opt\y@opt} +\def\y@opt#1{{\optstyle{#1}}} +\def\ys@opt#1{{\optstyle{#1}}\optpar{#1}} +\newrobustcmd*\optpar[1]{\marginpar{\hbox to \marginparwidth{\hss\y@opt{#1}}}} + +\newrobustcmd*\file[1]{{\filestyle{#1}}} +\newcommand*\pkgstyle[1]{\texttt{\textcolor{pkg}{#1}}} +\newcommand*\clsstyle[1]{\texttt{\textcolor{cls}{#1}}} +\newcommand*\libstyle[1]{\texttt{\textcolor{lib}{#1}}} +\newcommand*\envstyle[1]{\texttt{\textcolor{env}{#1}}} +\newcommand*\optstyle[1]{\textsf{\textcolor{opt}{#1}}} +\newcommand*\filestyle[1]{\texttt{\textcolor{file}{#1}}} +\colorlet{cls}{black} +\colorlet{lib}{black} +\colorlet{env}{black} +\colorlet{file}{black} +\colorlet{pkg}{black} +\definecolor{opt}{rgb}{0.5,0.16666,0} \newrobustcmd*\cs[1]{\texttt{\textbackslash #1}} \newrobustcmd*\cmd[1]{\texttt{{\escapechar=92\string#1}}} \def\macrodescstyle{\ttfamily\bfseries\color{macrodesc}} \def\macroargsstyle{\ttfamily} \def\envcodestyle{\ttfamily} -\def\verbstyle{\ttfamily} +\def\verbstyle{\verbatim@font} \def\metastyle{\normalfont\itshape\color{meta}} \def\margstyle{} -\def\oargstyle{\color{optional}\colorlet{meta}{metaoptional}} +\protected\def\Optional{\optionalon\optional} +\def\optionalstyle{\blendcolors*{!60!white}\color{black!75}} +\def\optionalon{\protected\def\optional{\optionalstyle}} +\def\optionaloff{\let\optional\relax} +\optionalon +\def\oargstyle{\optional} \def\pargstyle{} \def\aargstyle{} \def\sargstyle{\ttfamily\color{optional}} @@ -112,35 +159,46 @@ \def\read@Macro@arg{% \futurelet\@let@token\handle@Macro@arg } +\newcommand*\AlsoMacro{% + \begingroup\makeatletter + \AlsoMacro@ +} +\def\AlsoMacro@#1{% + \endgroup + \PrintMacroName{#1}% + \read@Macro@arg +} +\begingroup +\catcode`\|\active +\gdef\ydoc@short@AlsoMacro{% + \catcode`\|\active + \let|\AlsoMacro +} +\endgroup +\def\ydoc@macrocatcodes{% + \ydoc@short@AlsoMacro + \@makeother\'% + \@makeother\!% + \@makeother\[% + \@makeother\]% + \@makeother\(% + \@makeother\)% +} \def\handle@Macro@arg{% - \ifcase0% - \ifx\@let@token\bgroup1\else - \ifx\@let@token[\empty2\else - \ifx\@let@token(\empty3\else - \ifx\@let@token<\empty4\else - \ifx\@let@token*\empty5\else - \ifx\@let@token'\empty6\else - \ifx\@let@token!\empty7\else - \ifx\@let@token\@sptoken8\else - \ifx\@let@token\space9\else - \ifx\@let@token~9\else - \ifx\@let@token\AlsoMacro10\else - \ifx\@let@token\DescribeMacro11\fi - \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi - \relax - \unskip - \expandafter\end@Macro@args%0 - \or\expandafter\read@Macro@marg%1 - \or\expandafter\read@Macro@oarg%2 - \or\expandafter\read@Macro@parg%3 - \or\expandafter\read@Macro@angle%4 - \or\expandafter\read@Macro@sarg%5 - \or\expandafter\read@Macro@verb%6 - \or\expandafter\read@Macro@cmds%7 - \or\expandafter\read@Macro@rmspace%8 - \or\expandafter\read@Macro@addtoken%9 - \else%10- + \expandafter\let\expandafter\handler\csname handle@Macro@token@\meaning\@let@token\endcsname + \ifx\handler\relax + \def\handler{\ifhmode\unskip\fi\end@Macro@args}% \fi + \handler +} +\def\define@Macro@handler{% + \begingroup + \ydoc@macrocatcodes + \define@Macro@handler@ +} +\def\define@Macro@handler@#1{% + \endgroup + \@namedef{handle@Macro@token@\meaning#1}% } \def\end@Macro@args{% \y@egroup @@ -148,35 +206,79 @@ } \def\after@Macro@args{% } -\def\read@Macro@marg{% +\define@Macro@handler{\bgroup}{% \begingroup - \afterassignment\read@Macro@marg@ - \let\@let@token=% + \afterassignment\read@Macro@marg@ + \let\@let@token=% } \def\read@Macro@marg@{% - \setbox\@tempboxa\hbox\bgroup - \color@setgroup\bgroup - \aftergroup\color@endgroup - \aftergroup\egroup - \aftergroup\read@Macro@marg@@ + \bgroup + \margstyle{}% \let\end@Macro@args\empty% + {\ttfamily\braceleft}% + \aftergroup\read@Macro@marg@@ \read@Macro@arg } \def\read@Macro@marg@@{% - \@marg{\usebox\@tempboxa}% - \endgroup - \read@Macro@arg + {\ttfamily\braceright}% + \endgroup + \read@Macro@arg +} +\define@Macro@handler{[}[{% + \begingroup + \let\read@Macro@oarg@end\read@Macro@oarg@@end + \let\end@Macro@args\read@Macro@oarg@end + \oargstyle{}% + {\ttfamily[}%] + \read@Macro@arg +} +\define@Macro@handler{]}{% + \read@Macro@oarg@end +} +\def\read@Macro@oarg@@end#1]{% + #1% + {\ttfamily]}% + \endgroup + \read@Macro@arg +} +\def\read@Macro@oarg@end{\end@Macro@args} +\let\read@Macro@aarg@end\read@Macro@oarg@end +\let\read@Macro@parg@end\read@Macro@oarg@end +\define@Macro@handler{(}({% + \begingroup + \let\read@Macro@parg@end\read@Macro@parg@@end + \let\end@Macro@args\read@Macro@parg@end + \pargstyle{}% + {\ttfamily(}%) + \read@Macro@arg +} +\define@Macro@handler{)}{% + \read@Macro@parg@end } -\def\read@Macro@oarg[#1]{% - \@oarg{#1}\read@Macro@arg +\def\read@Macro@parg@@end#1){% + #1% + {\ttfamily)}% + \endgroup + \read@Macro@arg } -\def\read@Macro@parg(#1){% - \@parg{#1}\read@Macro@arg +\def\read@Macro@aarg<{% + \begingroup + \let\read@Macro@aarg@end\read@Macro@aarg@@end + \let\end@Macro@args\read@Macro@aarg@end + \aargstyle{}% + {\ttfamily<}% + \read@Macro@arg +} +\define@Macro@handler{>}{% + \read@Macro@aarg@end } -\def\read@Macro@aarg<#1>>{% - \@aarg{#1}\read@Macro@arg +\def\read@Macro@aarg@@end#1>>{% + #1% + {\ttfamily>}% + \endgroup + \read@Macro@arg } -\def\read@Macro@angle<{% +\define@Macro@handler{<}<{% \futurelet\@let@token\read@Macro@angle@ } \def\read@Macro@angle@{% @@ -189,33 +291,48 @@ \def\read@Macro@meta#1>{% \meta{#1}\read@Macro@arg } -\def\read@Macro@sarg#1{% +\define@Macro@handler**{% \sarg\read@Macro@arg } -\def\read@Macro@verb{% +\define@Macro@handler{'}'{% \begingroup \let\do\@makeother \dospecials + \@noligs + \@makeother\'% \obeyspaces \read@Macro@verb@ } -\def\read@Macro@verb@'#1'{% +\begingroup +\@makeother\'% +\gdef\read@Macro@verb@#1'{% \endgroup \ifx\relax#1\relax {\verbstyle{\string'}}% \else - {\verbstyle{#1}}% + {% + \frenchspacing + \@noligs\verbstyle{#1}}% \fi \read@Macro@arg } -\def\read@Macro@cmds!#1!{% +\endgroup +\define@Macro@handler!!#1!{% #1\relax \read@Macro@arg } -\@firstofone{\def\read@Macro@rmspace} {% +\define@Macro@handler{\@sptoken} {% \read@Macro@arg } -\def\read@Macro@addtoken#1{% +\define@Macro@handler{~}#1{% + #1\read@Macro@arg +} +\AtBeginDocument{% +\define@Macro@handler{~}#1{% + #1\read@Macro@arg +} +} +\define@Macro@handler{\space}#1{% #1\read@Macro@arg } \@ifundefined{DescribeMacro}{}{% @@ -224,10 +341,22 @@ \def\DescribeMacro{% \DescribeMacros \let\DescribeMacros\y@egroup + \optionalon \def\after@Macro@args{\endDescribeMacros}% \begingroup\makeatletter \Describe@Macro } +\def\DescribeScript#1{% + \DescribeMacros + \let\DescribeMacros\y@egroup + \optionalon + \def\after@Macro@args{\endDescribeMacros}% + \hbox\y@bgroup + \texttt{#1}% + \ydoc@macrocatcodes + \macroargsstyle + \read@Macro@arg~% +} \def\Describe@Macro#1{% \endgroup \edef\name{\expandafter\@gobble\string#1}% @@ -237,14 +366,14 @@ }% \hbox\y@bgroup \@ifundefined{href@impl@\name}{}{\hyperlink{impl:\name}}% - {\hypertarget{desc:\name}{\PrintMacroName{#1}}}% + {% + \hbox{\vbox to 0pt{\vss\hbox{\raisebox{4ex}{\hypertarget{desc:\name}{}}}}% + \PrintMacroName{#1}}% + }% \ydoc@macrocatcodes \macroargsstyle \read@Macro@arg } -\def\ydoc@macrocatcodes{% - \ydoc@short@AlsoMacro -} \newcommand*\MakeShortMacroArgs{% \@ifstar {\@MakeShortMacroArgs\Macro}% @@ -266,22 +395,8 @@ \begingroup\makeatletter \Describe@Macro } -\newcommand*\AlsoMacro{% - \begingroup\makeatletter - \AlsoMacro@ -} -\def\AlsoMacro@#1{% - \endgroup - \PrintMacroName{#1}% - \read@Macro@arg -} -\begingroup -\catcode`\|\active -\gdef\ydoc@short@AlsoMacro{% - \catcode`\|\active - \let|\AlsoMacro -} -\endgroup +\define@Macro@handler\AlsoMacro{} +\define@Macro@handler\DescribeMacro{} \newcommand*\MacroArgs{% \begingroup \def\end@Macro@args{\endgroup\xspace}% @@ -403,7 +518,7 @@ {\macrodescstyle{\strut \texttt{\char92}% \escapechar\m@ne - \string#1}}% + \string#1\strut}}% } \let\PrintLengthName\PrintMacroName \def\PrintEnvName#1#2{% @@ -414,21 +529,26 @@ } \def\PrintMacros{% \par\vspace\beforedescskip - \noindent\hspace*{\descindent}% - \ifdim\wd\descbox>\linewidth - \makebox[\linewidth][c]{\fbox{\hspace*{\descsep}\usebox{\descbox}\hspace*{\descsep}}} + \begingroup + \sbox\@tempboxa{\descframe{\usebox{\descbox}}}% + \Needspace*{\dimexpr\ht\@tempboxa+2\baselineskip\relax}% + \par\noindent + \ifdim\wd\@tempboxa>\dimexpr\linewidth-2\descindent\relax + \makebox[\linewidth][c]{\usebox\@tempboxa}% \else - \fbox{\hspace*{\descsep}\usebox{\descbox}\hspace*{\descsep}}% + \hspace*{\descindent}% + \usebox\@tempboxa \fi - \par\vspace\afterdescskip + \endgroup + \par + \vspace\afterdescskip + \par\noindent } -\let\PrintLength\PrintMacros -\def\PrintEnv{% - \par\vspace\beforedescskip - \noindent\hspace*{\descindent}% - \fbox{\hspace*{\descsep}\usebox{\descbox}\hspace*{\descsep}}% - \par\vspace\afterdescskip +\def\descframe#1{% + \fbox{\hspace*{\descsep}#1\hspace*{\descsep}}% } +\let\PrintLength\PrintMacros +\let\PrintEnv\PrintMacros \def\PrintSubEnv{% \hbox{\hbox{\usebox{\descbox}}}% } @@ -452,6 +572,34 @@ \endgroup \def\y@bgroup{\bgroup\color@setgroup} \def\y@egroup{\color@endgroup\egroup} +\newcommand*{\codeline}[1][c]{% + \codelinebefore + \hbox to \hsize\bgroup + \ifx i#1\hspace*{\leftmargin}\else + \ifx l#1\else\hss\fi + \fi + \let\xspace\relax + \hbox\bgroup + \aftergroup\codeline@end + \aftergroup#1% + \afterassignment\MacroArgs + \let\@let@token=% +} +\def\codeline@end#1{% + \ifx r#1\else\hss\fi + \egroup + \codelineafter +} +\newcommand*\codelinebefore{\par\smallskip\noindent} +\newcommand*\codelineafter {\par\smallskip\noindent} +\newenvironment{codequote}{% + \def\\{\newline\relax\MacroArgs}% + \par\smallskip\bgroup\leftskip=\leftmargin\rightskip=\rightmargin\noindent\MacroArgs} + {\par\egroup\smallskip\noindent\ignorespacesafterend} +\newenvironment{macroquote}{% + \def\\{\newline\relax\Macro}% + \par\smallskip\bgroup\leftskip=\leftmargin\rightskip=\rightmargin\noindent\Macro} + {\par\egroup\smallskip\noindent\ignorespacesafterend} \endinput %% %% End of file `ydoc-desc.sty'. -- cgit v1.2.3