diff options
Diffstat (limited to 'macros/latex/contrib/ffcode')
-rw-r--r-- | macros/latex/contrib/ffcode/DEPENDS.txt | 2 | ||||
-rw-r--r-- | macros/latex/contrib/ffcode/ffcode.dtx | 138 | ||||
-rw-r--r-- | macros/latex/contrib/ffcode/ffcode.pdf | bin | 487461 -> 493615 bytes |
3 files changed, 92 insertions, 48 deletions
diff --git a/macros/latex/contrib/ffcode/DEPENDS.txt b/macros/latex/contrib/ffcode/DEPENDS.txt index 935840f850..d55ae167dd 100644 --- a/macros/latex/contrib/ffcode/DEPENDS.txt +++ b/macros/latex/contrib/ffcode/DEPENDS.txt @@ -1,3 +1,3 @@ -hard xkeyval +hard pgfopts hard minted hard tcolorbox diff --git a/macros/latex/contrib/ffcode/ffcode.dtx b/macros/latex/contrib/ffcode/ffcode.dtx index e3c430c8de..e50bb899eb 100644 --- a/macros/latex/contrib/ffcode/ffcode.dtx +++ b/macros/latex/contrib/ffcode/ffcode.dtx @@ -50,7 +50,7 @@ %<package>\NeedsTeXFormat{LaTeX2e} %<package>\ProvidesPackage{ffcode} %<*package> -[2022-10-30 0.5.1 Fixed Font Code] +[2022-11-16 0.6.0 Fixed Font Code] %</package> %<*driver> \documentclass{ltxdoc} @@ -93,8 +93,7 @@ % \usepackage{ffcode} % \pagestyle{empty} % \begin{document} -% The function \ff{fibo()} -% is recursive: +% The function |fibo()| is recursive: % \begin{ffcode} % int fibo(int n) { % if (n < 2) { @@ -103,8 +102,8 @@ % return fibo(n-1)+fibo(n-2); % } % \end{ffcode} -% The line no.~\ref{ln:ret} -% terminates it. +% Line no.~\ref{ln:ret} returns \ff{n} +% and terminates it. % \end{document} % \end{docshot} @@ -141,10 +140,11 @@ % A pair of vertical lines decorate a TeX command inside the snippet. % If you want to print a single vertical line, use this: -% \ff{|\char`\\vert|}. +% ``\verb+|\char`\\vert|+''. % The command |\ff| behaves differently in math mode --- it doesn't % add gray frames: +% \docshotOptions{firstline=6,lastline=8} % \begin{docshot} % \documentclass{article} % \usepackage{ffcode} @@ -152,7 +152,7 @@ % \pagestyle{empty} % \begin{document} % \begin{equation*} -% x = \int_\ff{home}^N f(x). +% x = \int_{|home|}^N f(x). % \end{equation*} % \end{document} % \end{docshot} @@ -162,14 +162,14 @@ % You can highlight some lines in your |ffcode| environment, % or can use any other additional configuration parameters from % |minted| package: +% \docshotOptions{firstline=6,lastline=13} % \begin{docshot} % \documentclass{article} % \usepackage[paperwidth=3in]{geometry} % \usepackage{ffcode} % \pagestyle{empty} % \begin{document} -% \begin{ffcode*} -% {highlightlines={1,4-5}} +% \begin{ffcode*}{highlightlines={1,4-5}} % while (true) { % print("Hello!") % print("Enter your name:") @@ -189,28 +189,35 @@ % \section{Implementation} % \changes{v0.1.0}{2021/06/10}{Initial version} -% First, we parse package options: +% First, we parse package options with the help of +% \href{https://ctan.org/pkg/pgfopts}{pgfopts} package: +% \changes{v0.2.0}{2021/06/13}{Package options \texttt{nonumbers} and \texttt{noframes} added.} +% \changes{v0.3.0}{2021/09/07}{Package option \texttt{nocn} added.} +% \changes{v0.4.0}{2022/01/09}{Package option \texttt{nobars} added.} +% \changes{v0.6.0}{2021/11/14}{We use \texttt{pgfopts} instead of \texttt{xkeyval}.} +% \changes{v0.6.0}{2021/11/14}{Package option \texttt{novert} added, to disable redefinition of vertical bar.} % \begin{macrocode} -\RequirePackage{xkeyval} -\makeatletter -\DeclareOptionX{nopygments}{\PassOptionsToPackage{draft=true}{minted}} -\newif\ifff@noframes -\DeclareOptionX{noframes}{\ff@noframestrue} -% \changes{v0.4.0}{2022/01/09}{Package option "nobars" added.} -\newif\ifff@nobars -\DeclareOptionX{nobars}{\ff@nobarstrue} -% \changes{v0.2.0}{2021/06/13}{Package options "nonumbers" -% and "noframes" added.} -\newif\ifff@nonumbers -\DeclareOptionX{nonumbers}{\ff@nonumberstrue} -% \changes{v0.3.0}{2021/09/07}{Package option "nocn" added.} -\newif\ifff@nocn -\DeclareOptionX{nocn}{\ff@nocntrue} -\ProcessOptionsX\relax -\makeatother +\RequirePackage{pgfopts} +\pgfkeys{ + /ff/.cd, + nopygments/.store in=\ff@nopygments, + noframes/.store in=\ff@noframes, + nonumbers/.store in=\ff@nonumbers, + nobars/.store in=\ff@nobars, + novert/.store in=\ff@novert, + nocn/.store in=\ff@nocn, +} +\ProcessPgfOptions{/ff} % \end{macrocode} -% Then, we configure |minted| package: +% Then, we disable pygments for \href{https://ctan.org/pkg/minted}{minted}, if necessary: +% \begin{macrocode} +\makeatletter\ifdefined\ff@nopygments + \PassOptionsToPackage{draft=true}{minted} +\fi\makeatother +% \end{macrocode} + +% Then, we configure \href{https://ctan.org/pkg/minted}{minted} package: % \begin{macrocode} \RequirePackage{minted} \setminted{breaklines} @@ -222,8 +229,8 @@ % \begin{macro}{ffcode} % Then, we define |ffcode| environment: % \begin{macrocode} -\makeatletter\ifff@nonumbers - \ifff@nobars +\makeatletter\ifdefined\ff@nonumbers + \ifdefined\ff@nobars \newminted[ffcode]{text}{} \else \newminted[ffcode]{text}{framesep=6pt, @@ -232,8 +239,8 @@ \else \renewcommand{\theFancyVerbLine}{\textcolor{gray}% {\tiny\oldstylenums{\ttfamily\arabic{FancyVerbLine}}}} - \ifff@nocn - \ifff@nobars + \ifdefined\ff@nocn + \ifdefined\ff@nobars \newminted[ffcode]{text}{ linenos,numbersep=2pt } @@ -244,7 +251,7 @@ } \fi \else - \ifff@nobars + \ifdefined\ff@nobars \newminted[ffcode]{text}{ firstnumber=last,linenos,numbersep=2pt } @@ -260,12 +267,11 @@ % \end{macro} % \begin{macro}{\ff@print} -% Then, we define supplementary commands |\ff@print| and |\ff@printx|: -% \changes{v0.5.1}{2022/10/30}{Now, the command "ff" ignores italic and bold and always prints "texttt" as it should be.} +% Then, we define a supplementary macro |\ff@print|: +% \changes{v0.5.1}{2022/10/30}{Now, the command \texttt{ff} ignores italic and bold and always prints \texttt{\char`\\texttt} as it should be.} % \begin{macrocode} \makeatletter -\newcommand\ff@print{\begingroup\obeyspaces\ff@printx} -\newcommand\ff@printx[1]{\textnormal{\texttt{#1}}\endgroup} +\newcommand\ff@print[1]{\textnormal{\texttt{#1}}} \makeatother % \end{macrocode} % \end{macro} @@ -279,22 +285,60 @@ % \end{macrocode} % \end{macro} -% \begin{macro}{\ff} -% Finally, we define |\ff| command: +% \begin{macro}{tcolorbox} +% Then, we use \href{https://ctan.org/pkg/tcolorbox}{tcolorbox} to define |\ff@box| +% command for a gray box around verbatim text block: % \begin{macrocode} -\makeatletter\ifff@noframes - \newcommand\ff[1]{\ff@rule\ff@print{#1}} -\else +\makeatletter +\ifdefined\ff@noframes\else \RequirePackage{tcolorbox} - \newtcbox\ff@box{nobeforeafter,colframe=gray!80!white, + \newtcbox\ff@box{nobeforeafter,colframe=gray!80!white, colback=gray!5!white,boxrule=0.1pt,arc=1pt, boxsep=1.2pt,left=0.5pt,right=0.5pt,top=0.2pt,bottom=0.2pt, tcbox raise base} - \newcommand\ff[1]{\relax\ifmmode% - {\ff@rule\ff@print{#1}}% +\fi +\makeatother +% \end{macrocode} +% \end{macro} + +% \begin{macro}{\ff@x} +% Then, we define |\ff@x| internal command for printing a piece of fixed-width-font text: +% \begin{macrocode} +\makeatletter +\NewDocumentCommand\ff@x{v}{% + \ifdefined\ff@noframes% + \ff@rule\ff@print{#1}% \else% - {\ff@box{\ff@rule\ff@print{#1}}}% - \fi} + \relax\ifmmode% + \ff@rule\ff@print{#1}% + \else% + \ff@box{\ff@rule\ff@print{#1}}% + \fi% + \fi% +} +\makeatother +% \end{macrocode} +% \end{macro} + +% \begin{macro}{\ff} +% Then, we define |\ff| macro: +% \begin{macrocode} +\makeatletter +\def\ff{\ff@x} +\makeatother +% \end{macrocode} +% \end{macro} + +% \begin{macro}{novert} +% Finally, we let vertical bars work similar to |\ff|, as suggested +% \href{https://tex.stackexchange.com/a/665105/1449}{here} +% and \href{https://tex.stackexchange.com/a/665303/1449}{here} +% (unless |novert| package option is used): +% \begin{macrocode} +\makeatletter\ifdefined\ff@novert\else + \catcode`\|\active + \AtBeginDocument{\catcode`\|\active\protected\def|{\ff@x|}} + \catcode`\| 12 % \fi\makeatother % \end{macrocode} % \end{macro} diff --git a/macros/latex/contrib/ffcode/ffcode.pdf b/macros/latex/contrib/ffcode/ffcode.pdf Binary files differindex a24f23e4b0..f87101ad3f 100644 --- a/macros/latex/contrib/ffcode/ffcode.pdf +++ b/macros/latex/contrib/ffcode/ffcode.pdf |