summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/ffcode/ffcode.sty
blob: ee3c25fed7a8f1747212a435b04118b3b19105ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
% (The MIT License)
%
% Copyright (c) 2021-2022 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
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in all
% copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
% SOFTWARE.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ffcode}[2022/09/12 0.4.4 Fixed Font Code]

\RequirePackage{xkeyval}

\makeatletter
\DeclareOptionX{nopygments}{\PassOptionsToPackage{draft=true}{minted}}
\newif\ifff@noframes
\DeclareOptionX{noframes}{\ff@noframestrue}
\newif\ifff@nobars
\DeclareOptionX{nobars}{\ff@nobarstrue}
\newif\ifff@nonumbers
\DeclareOptionX{nonumbers}{\ff@nonumberstrue}
\newif\ifff@nocn
\DeclareOptionX{nocn}{\ff@nocntrue}
\ProcessOptionsX\relax
\makeatother

\RequirePackage{minted}

\setminted{breaklines}
\setminted{escapeinside=||,mathescape}
\setminted{highlightcolor=gray!30}
\usemintedstyle{bw}

\makeatletter\ifff@nonumbers
  \ifff@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}}}}
  \ifff@nocn
    \ifff@nobars
      \newminted[ffcode]{text}{
        linenos,numbersep=2pt
      }
    \else
      \newminted[ffcode]{text}{
        framesep=6pt,framerule=1pt,rulecolor=gray,frame=leftline,
        linenos,numbersep=2pt
      }
    \fi
  \else
    \ifff@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
      }
    \fi
  \fi
\fi\makeatother

\makeatletter
\newcommand\ff@print{\begingroup\obeyspaces\ff@printx}
\newcommand\ff@printx[1]{\texttt{#1}\endgroup}
\makeatother

\makeatletter\newcommand\ff@rule{\vrule height 6pt depth 1pt width 0pt}
\makeatletter\ifff@noframes
  \newcommand\ff[1]{\ff@rule\ff@print{#1}}
\else
  \RequirePackage{tcolorbox}
    \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}}\else{\ff@box{\ff@rule\ff@print{#1}}}\fi}
\fi\makeatother

\endinput