OthersHow can I use a keyval as parameter for minted?

Information and discussion about other tools not listed above.
Post Reply
acombo
Posts: 2
Joined: Fri Apr 20, 2012 10:32 am

How can I use a keyval as parameter for minted?

Post by acombo »

I'm trying to use minted inclusion of source code in a document. Everything works fine if I write (or use a command) as the filename, but if I first store the filename in a key (using keyval) an error occurs and mint does not recognizes the file. Bellow is the code... and the line (commented) that gives the error, and the error itself. Thanks for you help.

Code: Select all

\documentclass{article}

% Preamble Setting for {minted} package
\usepackage{minted}
\usemintedstyle{friendly}  
% Specify Custom Styles for minted Source Codes
\newmintedfile[codec]{c}{linenos=true} 

\usepackage{keyval}% http://ctan.org/pkg/keyval 

\newcommand{\tempsrc}{./tmpsrc/}   % Just a path!
\newcounter{cntTmp}

\makeatletter
\newcommand{\gitRepoDir}{S:/temp/git_test/}
\newcommand{\tmpSrcDir}{./tmpsrc/}
\newcommand{\mysome}[1]{#1}
% \gFile{<Init Directory>}{<Tag>}{<Source Directory>}{Filename}
\newcommand{\gFile}[4]{
% Define Key
\define@key{}{fdTmp\arabic{cntTmp}}[]{tmp#2#4}
\stepcounter{cntTmp}
}
\makeatother

\begin{document}

- Add a key.

\gFile{src}{first-tag}{./}{test.txt}

- End Key creation. \newline
- Verify SETKEYS (for fdTmp0): \setkeys{}{fdTmp0} \newline


-- At this point assume the following files exist:\newline
+++++ \setkeys{}{fdTmp0} \newline

- Now the minted command WITH file name.


\codec[firstline=5, lastline=50]{\tempsrc tmpfirst-tagtest.txt}

- Now the same command, but where the parameter is given by setkeys.

%%% HERE LIES THE PROBLEM   
%\codec[firstline=5, lastline=50]{\tempsrc \setkeys{}{fdTmp0}}

% The following error appears if the above line is added:
% Traceback (most recent call last): File "<string>", line 1, in <module> IOError: [Errno 2] No such file or directory: './tmpsrc/\\def KV@FV@{KV@@}\\let \\par '


\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Post Reply