I am writing a document where I need to put down gnuplot code I've used. What I want is to copy this gnuplot code from final pdf file of this document and paste it in gnuplot itself so it can work.
I've tried package listings, but when I copy the code from final pdf file, it's broken. Random spaces between letters, wrong spacing.
\usepackage{listings}
\begin{document}
\begin{lstlisting}
set terminal pngcairo size 350,262 enhanced font 'Verdana,10'
abc = 'abcdefghijklmnop'
f(x) = A * (exp(-x/t) - exp(-x/T))
set xrange [0.04:120]
set yrange [0:21]
set xlabel "Time [{/Symbol m} s]"
set ylabel "Number of detections"
do for [i=16:16] {
letter = substr(abc, i, i)
do for [j=1:10] {
num = sprintf("%02d", j)
file = "rf_" . letter . "_" . num . ".dat"
file2 = "rf_" . letter . "_" . num . ".png"
print file
A = 20
t = 12
T = 4
fit[0.04:50] f(x)+c file u 1:3 via A,t,T,c
set output file2
plot file u 1:3 with lines t 'naměřená data', f(x) t 'fitovací funkce'
}
}
\end{lstlisting}
\end{document}
I found also package verbatim. It's atually better, but the spacing is still wrong and gnuplot can't handle it. (similar code, just using package verbatim)
Do you know any package which can help me?
P.S. - sorry for bothering if this problem is somewhere, i couldn't find any similar issue in here
mintedpackage the code is usually preserved well for copying and pasting from the pdf. However, also with this package indentation spaces are usually not preserved (see for example https://tex.stackexchange.com/questions/459591/how-to-keep-formating-when-copy-paste-code-sections-with-minted). However, spaces within lines are usually preserved, and I could succesfully copy your example code from the pdf to gnuplot withmintedand run it in gnuplot (although it did not work because I was missingrf_p_01.dat). – Marijn Mar 12 '20 at 12:10@Marjin - Ok thank you, i will try this and let you now.
– Minsck Mar 14 '20 at 11:49