gpoore / minted

minted is a LaTeX package that provides syntax highlighting using the Pygments library. Highlighted source code can be customized using fancyvrb.
1.73k stars 125 forks source link

Font settings (migrating from lst-listings) #366

Closed goyalyashpal closed 1 year ago

goyalyashpal commented 1 year ago

Summary

So, i needed some pointers for achieving the same results.

I looked at this issue as well 365 which mentions setting via fancyvrb package i guess, but couldn't figure out how to use that in \setminted{}

Details

The basic settings I need & couldn't find are:

Following are my settings for the listings package:

\documentclass[12pt,a4paper,oneside,titlepage,final]{report}
\renewcommand*\rmdefault{ptm}
\newcommand{\setfsize}[1]{\fontsize{#1}{
        \dimexpr #1 * 12 / 10}\selectfont}
   ...

% 2023.05.04 These all work with \fvset (fancy-verb-set) too
% These worked
\setminted{ %
    % Inclusion/Exclusion below
    breaklines=true,
    breakafter=./_,             % For long links
    xleftmargin=10pt,
    numbers=left,                   % linenos=true,
    numberblanklines=false,
    stepnumber=2,
    % showspaces=true,      % showstringspaces WANTED
}

% These ERRORED/didn't work
% \setminted{ %
    % Basic Stuff
    % inputpath=\src,
    % language=html,        % language not optional in \inputminted{LANGUAGE}{FILE}
    % otherkeywords=???,
    %
    % Styles Below
    % size's already handled in documentclass option
    % fontfamily=ptm,
    % fontsize=\setfzie{12pt},
    %
    % basicstyle=,%\setfsize{12pt}, 
    % For model: Gray (Integer grayscale)
    % keywordstyle=\mdseries, %\textbf,
    % stringstyle=\normalfont, %\color[gray]{0},
    % commentstyle=\color[gray]{0.6},
    % numberstyle=\scriptsize\color[gray]{0.7},
% }

\lstset{ %
    % Basic stuff
    inputpath=\src,
    language=html,
    % otherkeywords={cin,cout,endl},
    %
    % Inclusion/Exclusion below
    showstringspaces=false,
    breaklines=true,
    xleftmargin=10pt,
    numbers=left,
    stepnumber=1,
    %
    % Styles Below
    % size's already handled in documentclass option
    basicstyle=,%\setfsize{12pt}, 
    % For model: Gray (Integer grayscale)
    keywordstyle=\mdseries, %\textbf,
    stringstyle=\normalfont, %\color[gray]{0},
    commentstyle=\color[gray]{0.6},
    numberstyle=\scriptsize\color[gray]{0.7},
}

LEFT: minted , RIGHT: listings

Versions

goyalyashpal commented 1 year ago

but some curious details:

Future versions of ‘fancyvrb’ and ‘listings’ packages are planned to cooperate, ... - fancyvrb-doc at I.7 Pretty Printing (page 23)

gpoore commented 1 year ago

minted only provides four font settings: fontfamily, fontsize, fontshape, fontseries. These simply pass options on to fancyvrb internally; fancyvrb actually does the code typesetting. fancyvrb only provides built-in support for a few fonts, so you will have to configure it for what you want, which will partly depend on whether you are using pdfTeX, XeTeX, or LuaTeX. TeX.SE may be helpful.

There is no minted equivalent of the listings setting inputpath.

There is no "cooperation" between fancyvrb and listings. There are some settings in common, and in some situations they can be used together. But they often have different settings and different approaches.

goyalyashpal commented 1 year ago

i am using pdflatex.

also, fancyvrb doesnt have any issue tracker/community post discussions where i can file suggestions to 'em right? like here, gitlab, s_forge, c_berg, s_hunt etc...

I had a suggestion regarding to its numberblanklines=false option, its awesome, but the suggestion is to expand it to accept values equivalent to: "normalcount", "Dont count and displaydashes", "dont count display nothing"

or maybe to have two settings:

this countblanklines will only affect when XN0R of its vale with value of numberblanklines results in False i.e. when these both are NOT having same boolean value.

numberblanklines=false numberblanklines=true
countblanklines=false normal (current behaviour of numberblanklines=false) show dashes - for blank lines [MY WANT]
countblanklines=true just dont show the number for blank lines, but count them [USEFUL FOR COMPILER ERRORS] normal (current behaviour for normalblanklines=true)
gpoore commented 1 year ago

For something like Times Roman under pdfTeX, you can try this:

\usepackage{mathptmx}
\usepackage{minted}
\setminted{fontfamily=ptm}

If you want to customize things further, you'll probably need to go through the respective documentation or perhaps search https://tex.stackexchange.com/.

fancyvrb doesn't have a git repo or issue tracker anywhere that I'm aware of.

goyalyashpal commented 1 year ago

so, font size to 12, and no formatting for anything (i.e. all black) except comments will still require going to fancyvrb?

gpoore commented 1 year ago

Size: \documentclass[12pt]{article}, \setminted{fontsize=\large}, etc.

Color: \setminted{style=bw}. If you really want gray comments, you'll have to customize the comment token macro. You'll need something like this in the preamble:

\makeatletter
\appto{\minted@patch@PYGZhy}{%
  \def\PYG@tok@c{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.5,0.5,0.5}{##1}}}}
\makeatother
goyalyashpal commented 1 year ago

thanks for all the help. i had some thoughts related to this in direction of maybe some linking minted API with listings instead of fancyvrb...

but couldnt formalise it very well, so, wiill leave it at that

thabks again.

goyalyashpal commented 1 year ago

Just a small note, color mode gray also works instead of rgb

- \def\PYG@tok@c{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.5,0.5,0.5}{##1}}}}
+ \def\PYG@tok@c{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[gray]{0.5}{##1}}}}
goyalyashpal commented 1 year ago

For some of these options in lstinputlisting: linerange , lastline, consecutivenumbers, firstnumber i have seen existing options in either of minted or fancyvrb documentation, will post here someday later

\lstinputlisting[%
    linerange={10-40,48-48,56-107}, 
    % lastline=108, 
    % consecutivenumbers=false
]{Rational.h}
\lstinputlisting[%
    firstnumber=last, 
    linerange={12}, 
    % consecutivenumbers=true,
]{rational.cpp}
goyalyashpal commented 1 year ago

\setminted{fontfamily=ptm} - @ gpoore at https://github.com/gpoore/minted/issues/366#issuecomment-1522543607

with setminted or fvset using ptm font; the characters like _ , <, { etc from the source code are not rendering properly.

LEFT: minted , RIGHT: listings

gpoore commented 1 year ago

\usepackage[T1]{fontenc}

goyalyashpal commented 8 months ago

linerange, lastline, consecutivenumbers, firstnumber

Only linerange remains now