Closed goyalyashpal closed 7 months ago
Not sure I get your point.
\inputminted[<options>]{<lang>}{<filename>}
accepts <options>
as its first opt-arg, and there's \newmintedfile
that can create custom versions of \inputminted
, just like \newminted
can create custom minted
env.
hi @muzimuzhi the point is simple
newmintedfile
then use the "foo*" to override base ones or specify other options specific to the particular listing.newminted
exist
https://github.com/gpoore/minted/blob/13e25d05cd382cf55f66636e0b1a91d94c2b4e4c/source/minted.dtx#L1501
https://github.com/gpoore/minted/blob/13e25d05cd382cf55f66636e0b1a91d94c2b4e4c/source/minted.dtx#L1502-L1511
https://github.com/gpoore/minted/blob/13e25d05cd382cf55f66636e0b1a91d94c2b4e4c/source/minted.dtx#L1512-L1514ohhhhww sorry, i meant starred version of newmintedfile
env
\assign @me
I'd like to work on this.
So you want \inputminted
to accept an optional star which applies showspaces
option and a revised \newmintedfile
to define starred variant command (not environment) in addition?
Try this:
\begin{filecontents}[noheader]{test.py}
def f(x):
return x * x + 1
\end{filecontents}
\documentclass{article}
\usepackage{minted}
\makeatletter
\RenewDocumentCommand{\inputminted}{ s O{} m m }{%
\IfBooleanTF{#1}
{\inputminted@i{showspaces,#2}{#3}{#4}}
{\inputminted@i{#2}{#3}{#4}}%
}
\ifthenelse{\boolean{minted@draft}}
{\newcommand{\inputminted@i}[3]{%
\begingroup
\minted@configlang{#2}%
\setkeys{minted@opt@cmd}{#1}%
\minted@fvset
\minted@inputlanglinenoson
\VerbatimInput{#3}%
\minted@inputlanglinenosoff
\endgroup}}%
{\newcommand{\inputminted@i}[3]{%
\begingroup
\minted@configlang{#2}%
\setkeys{minted@opt@cmd}{#1}%
\minted@fvset
\minted@inputlanglinenoson
\minted@pygmentize[#3]{#2}%
\minted@inputlanglinenosoff
\endgroup}}
% #1 = macro name, #2 = language, #3 = options
\renewcommand{\newmintedfile}[3][]{%
\ifthenelse{\equal{#1}{}}
{\def\minted@shortname{#2file}}
{\def\minted@shortname{#1}}%
% ##1 = star, ##2 = options, ##3 = filename
\ExpandArgs{c}\NewDocumentCommand{\minted@shortname}{ s O{} m }{%
\IfBooleanTF{##1}
{\inputminted@i{#3,showspaces,##2}{#2}{##3}}
{\inputminted@i{#3,##2}{#2}{##3}}}}
\makeatother
% defines \pythonfile*[<options>]{<filename>}
\newmintedfile{python}{linenos}
\begin{document}
\inputminted{python}{test.py}
\inputminted*{python}{test.py}
\pythonfile{test.py}
\pythonfile*{test.py}
\end{document}
you want
\inputminted
to accept an optional star
no, only the newmintedfile
\begin{filecontents}[noheader]{test.py} def f(x): return x * x + 1 \end{filecontents}
wow filecontents, thats so cool
you want
\inputminted
to accept an optional starno, only the newmintedfile
Then that seems inconsistent to me: \inputminted
doesn't have a starred version, but the custom versions of \inputminted
created by \newmintedfile
have.
i would have shared an illustrative working example, but i couldnt find my explorations with defining starred commands.
i will come up with something in few days.
newmintedfile (pg=29): If no ⟨macro name⟩
is given, then the macro is called \⟨language⟩file
.
\newmintedfile[⟨macro name⟩]{⟨language⟩}{⟨options⟩}
inputminted (pg=8): Its syntax is
\inputminted[⟨options⟩]{⟨language⟩}{⟨filename⟩}
\expandafter\newcommand\csname\minted@shortname\endcsname[2][]{
\inputminted[#3,##1]{#2}{##2}}}
as the \newcommand
above gives ##1
to the \inputminted
's options [ ]
, it works exactly as it should.
following the starred environments by \newminted
i shared above, i was trying to pass those in curly braces, which was resulting in the issues.
Working sample:
\begin{filecontents}[noheader]{./test.mysql}
mysql-> select * from firstLine;
mysql-> select * from secondLine;
mysql-> \help contents
mysql-> \h contents
\end{filecontents}
% \documentclass[12pt,a4paper,oneside,titlepage,final]{report}
\documentclass{article}
\usepackage{minted}
\newmintedfile[inputmintedpsql]{psql}{
% bgcolor=lightgray,
style=bw,
keywordcase=upper,
linenos=true,
}
\begin{document}
\inputmintedpsql[firstline=2, lastline=2]{test.mysql}
% \inputmintedpsql*{firstline=2, lastline=2}{test.mysql} % <-- I was trying to do this due to confusion
\inputmintedpsql[firstline=3, lastline=4, keywordcase=lower]{test.mysql}
\end{document}
newmintedfile
env to specify additional options (similar to fornewminted
s env)useful for options which are fundamentally custom to each use - like firstline etc.