Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font settings (migrating from lst-listings) #366

Closed
goyalyashpal opened this issue Apr 24, 2023 · 12 comments
Closed

Font settings (migrating from lst-listings) #366

goyalyashpal opened this issue Apr 24, 2023 · 12 comments

Comments

@goyalyashpal
Copy link

goyalyashpal commented Apr 24, 2023

Summary

  • I am migrating over to minted package from listings package due to its limitations
    (bad parsing in html comments, lacking css support, bad text layer rendering),
  • but i can't find fine grained options in the minted manual.
  • and it ain't respecting my document wide font settings either.
  • I tried searching the web: this and that, but couldn't narrow down the results to minted package specific

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:

  • font settings:
    • [MUST] main: 12pt, times new roman, black (even for keywords)
    • comments: 12 pt, times new roman, gray
    • line number: any smaller font size, times new roman, lighter gray
  • source location: to avoid typing complete relative location again and again
  • [DONE] [MUST] breaklines to soft wrap the long lines

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

  • listings: 1.9
  • minted: 2.7
@goyalyashpal
Copy link
Author

goyalyashpal commented Apr 24, 2023

but some curious details:

  • [DONE} \RequirePackage[gray]{xcolor} or \usepackage[gray]{xcolor} was setting that.
    Overleaf tutorial: Code Highlighting with minted shows the output as colored,
    whereas the output in my "document" is shown as grayscale too, so, it means smth is setting that

  • mention of "cooperation" between fancyvrn and listings package

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

@gpoore
Copy link
Owner

gpoore commented Apr 25, 2023

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
Copy link
Author

goyalyashpal commented Apr 25, 2023

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:

  • countblanklines=[boolean: true | false]
  • numnerblanklines=[boolean: true | false]

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
Copy link
Owner

gpoore commented Apr 25, 2023

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
Copy link
Author

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

@gpoore
Copy link
Owner

gpoore commented Apr 26, 2023

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 goyalyashpal closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2023
@goyalyashpal
Copy link
Author

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
Copy link
Author

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 goyalyashpal changed the title Font settings Font settings (migrating from lst-listings) May 4, 2023
@goyalyashpal
Copy link
Author

goyalyashpal commented May 4, 2023

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
Copy link
Author

goyalyashpal commented May 14, 2023

\setminted{fontfamily=ptm}
- @ gpoore at #366 (comment)

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

LEFT: minted , RIGHT: listings

@gpoore
Copy link
Owner

gpoore commented May 14, 2023

\usepackage[T1]{fontenc}

@goyalyashpal
Copy link
Author

linerange, lastline, consecutivenumbers, firstnumber

  • firstnumber

    minted/source/minted.dtx

    Lines 1318 to 1320 in 13e25d0

    % \item[firstline (integer) (1)]
    % The first line to be shown.
    % All lines before that line are ignored and do not appear in the output.

  • lastline

    % \item[lastline (integer) (\meta{last line of input})]

  • inputlanglinenos

    minted/source/minted.dtx

    Lines 917 to 918 in 13e25d0

    % \DescribeMacro{inputlanglinenos=\meta{boolean} (default:~false)}
    % This enables |langlinenos| and causes it to apply to |\inputminted| (and custom commands based on it) in addition to |minted| environments and |\mint| commands (and custom environments/commands based on them).

Only linerange remains now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants