0

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

Minsck
  • 1
  • 1
    There is no reliable method, see e.g. https://tex.stackexchange.com/a/472112/2388 and https://tex.stackexchange.com/a/323354/2388. – Ulrike Fischer Mar 11 '20 at 21:20
  • Why do yo do this? Just cut out the code from LaTeX source. Or arrange for LaTeX to run gnuplot from the source, look around there are packages doing this. – vonbrand Mar 11 '20 at 23:57
  • With the minted package 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 with minted and run it in gnuplot (although it did not work because I was missing rf_p_01.dat). – Marijn Mar 12 '20 at 12:10
  • -> vonbrand - I need to do this because the file people get will be .pdf. Not .tex. They have only one option to copy the code -> ctrl C or some OCR program. I want to give them the easiest way possible to copy that code.

    @Marjin - Ok thank you, i will try this and let you now.

    – Minsck Mar 14 '20 at 11:49

0 Answers0