diff options
Diffstat (limited to 'macros/latex/contrib/ffcode/ffcode.dtx')
-rw-r--r-- | macros/latex/contrib/ffcode/ffcode.dtx | 95 |
1 files changed, 31 insertions, 64 deletions
diff --git a/macros/latex/contrib/ffcode/ffcode.dtx b/macros/latex/contrib/ffcode/ffcode.dtx index e8c71aa8ed..ffd57f6d02 100644 --- a/macros/latex/contrib/ffcode/ffcode.dtx +++ b/macros/latex/contrib/ffcode/ffcode.dtx @@ -1,7 +1,7 @@ % \iffalse meta-comment % (The MIT License) % -% Copyright (c) 2021-2022 Yegor Bugayenko +% Copyright (c) 2021-2024 Yegor Bugayenko % % Permission is hereby granted, free of charge, to any person obtaining a copy % of this software and associated documentation files (the 'Software'), to deal @@ -50,7 +50,7 @@ %<package>\NeedsTeXFormat{LaTeX2e} %<package>\ProvidesPackage{ffcode} %<*package> -[2022-12-02 0.8.0 Fixed Font Code] +[2024-01-10 0.9.0 Fixed Font Code] %</package> %<*driver> \documentclass{ltxdoc} @@ -97,7 +97,7 @@ % \begin{ffcode} % int fibo(int n) { % if (n < 2) { -% return n; |\label{ln:ret}| +% return n; (*@ \label{ln:ret} @*) % } % return fibo(n-1)+fibo(n-2); % } @@ -109,12 +109,6 @@ % \section{Package Options} -% \DescribeMacro{nopygments} -% You have to run |pdflatex| with |--shell-escape| flag -% in order to let |minted| (the package we use) to run Pygments -% and format the code. If you don't want this to happen, -% just use |nopygments| option. - % \DescribeMacro{noframes} % If you want to omit the light gray frames around |\ff| % texts, use the package option |noframes|. @@ -194,7 +188,7 @@ % You can highlight some lines in your |ffcode| environment, % or can use any other additional configuration parameters from -% |minted| package: +% |fancyvrb| and |fvextra| packages: % \docshotOptions{firstline=6,lastline=13} % \begin{docshot} % \documentclass{article} @@ -202,19 +196,19 @@ % \usepackage{ffcode} % \pagestyle{empty} % \begin{document} -% \begin{ffcode*}{highlightlines={1,4-5}} +% \begin{ffcode}[backgroundcolor=\color{gray!20}] % while (true) { -% print("Hello!") +% (*@\textcolor{red}{print("Hi!")}@*) % print("Enter your name:") % scan(x) -% print("You name is " + x) +% print("You name | " + x) % } -% \end{ffcode*} +% \end{ffcode} % \end{document} % \end{docshot} -% Using this second argument of |ffcode*| (with the trailing asterisk), -% you can provide any other options from |minted| package to the +% Using this second argument of |ffcode|, +% you can provide any other options from the |listings| package to the % snippet. % \StopEventually{} @@ -237,7 +231,6 @@ /ff/.cd, bold/.store in=\ff@bold, sf/.store in=\ff@sf, - nopygments/.store in=\ff@nopygments, noframes/.store in=\ff@noframes, nonumbers/.store in=\ff@nonumbers, nobars/.store in=\ff@nobars, @@ -247,59 +240,33 @@ \ProcessPgfPackageOptions{/ff} % \end{macrocode} -% 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: +% Then, we configure the \href{https://ctan.org/pkg/listings}{listings} package: +% \changes{v0.9.0}{2024/01/09}{The \texttt{minted} package is replaced by the \texttt{listings} package.} % \begin{macrocode} -\RequirePackage{minted} -\setminted{breaklines} -\setminted{escapeinside=||,mathescape} -\setminted{highlightcolor=gray!25} -\usemintedstyle{bw} +\RequirePackage{xcolor} +\RequirePackage{listings} % \end{macrocode} % \begin{macro}{ffcode} -% Then, we define |ffcode| environment: +% Then, we define the |ffcode| environment and its supplementary |ffcode*| counterpart: % \begin{macrocode} -\makeatletter\ifdefined\ff@nonumbers - \ifdefined\ff@nobars - \newminted[ffcode]{text}{} - \else - \newminted[ffcode]{text}{framesep=6pt, - framerule=1pt,rulecolor=gray,frame=leftline} - \fi -\else - \renewcommand{\theFancyVerbLine}{\textcolor{gray}% - {\tiny\oldstylenums{\ttfamily\arabic{FancyVerbLine}}}} - \ifdefined\ff@nocn - \ifdefined\ff@nobars - \newminted[ffcode]{text}{ - linenos,numbersep=2pt - } - \else - \newminted[ffcode]{text}{ - framesep=6pt,framerule=1pt,rulecolor=gray, - frame=leftline,linenos,numbersep=2pt - } - \fi - \else - \ifdefined\ff@nobars - \newminted[ffcode]{text}{ - firstnumber=last,linenos,numbersep=2pt - } - \else - \newminted[ffcode]{text}{ - framesep=6pt,framerule=1pt,rulecolor=gray, - frame=leftline,firstnumber=last,linenos,numbersep=2pt - } +\makeatletter +\lstnewenvironment{ffcode}[1][] + { + \lstset{breaklines} + \lstset{escapeinside={(*@}{@*)}} + \lstset{basicstyle={\ttfamily}} + \lstset{columns=fullflexible} + \ifdefined\ff@nonumbers\else + \lstset{numbers=left,numbersep=5pt,numberstyle={\tiny\sffamily\color{gray}}} \fi - \fi -\fi\makeatother + \ifdefined\ff@nobars\else + \lstset{frame=leftline,framerule=.3pt,rulecolor={\color{gray}}} + \ifdefined\ff@nocn\else\fi + \lstset{#1} + } + {} +\makeatother % \end{macrocode} % \end{macro} |