%run with pdftex or luatex \ifdefined\outputmode \outputmode=1 \fi \unless\ifdefined\theend \let\theend\end \def\begin#1{\csname #1\endcsname} \def\end#1{\csname end#1\endcsname} \fi \tenrm \input Tcode_py.tex %Remove the stretch and shrink of spaces, and the extra space inserted after e.g. a full stop. %A fixed-wdith font should not have those wider spaces. \TcodeHook\exP{\the\TcodeHook\frenchspacing} %Use of \PrePrintHook. Just as example \newtoks\usedwords \usedwords={\SelectCodeFont} \let\PrePrintHook\HookOnlyKnown %This way, uncategorized words are not passed to \KnownWordHook \def\KnownWordHook{%If you want to handle also uncategorized words, omit the previous line and write here \PrePrintHook instead of \KnownWordHook \exP\def\exP\temp\exP{\FormatToApply}%\FormatToApply is protected, but we want it expanded in the next line \edef\temp{\global\usedwords{\the\usedwords{\temp\the\WordToPrint}\ }}\temp } Some python code. {\catcode`@=11 \def\CBeginLine{{\color{blue}>> }\@parsecode} \begin{Code} pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')] pairs.sort(key=lambda pair: pair[1]) pairs \end{Code} } \CodeFramewd=0pt \DefColor{bkgcolor}{.92, .92, .94} \CsnippetColor \def\CsnippetBkg{bkgcolor} \begin{Code} import fileinput def process_line(line): # Ignore what comes before the coordinates i=line.find('((('); if i == -1 : return line= line[i+3:] i=line.rfind(')))",'); #Find de last and only @{)))",} fname= line[i+5:].strip() #The name comes after )))", chunks= line[0:i].split(')),((') print(fname+'.xy') file= open(fname+'.xy', 'w', encoding="utf-8", newline='\n') file.write(f"% {fname}\n") for chunks in chunks: for ss in chunks.split('),('): file.write('\n') for ss in ss.split(','): ss=ss.split(' ') file.write(f"{ss[1][0 : ss[1].find('.')+5]}\ {ss[0][0 : ss[1].find('.')+5]}\n") file.close() if __name__ == "__main__": for line in fileinput.input(encoding="utf-8") : process_line(line) \end{Code} The words in python code belonging to some category used in this file are: \medskip \raggedright\noindent\the\usedwords\par \theend