How to keep formating when copy-paste code sections with minted?











up vote
1
down vote

favorite












I am using the minted package for syntax highlighting code in my slides, but I have some problem to make this code easily copyable directly from the PDF to the console. it seems that the whitespaces used to format the code totally disappear when we select the code on the screen.



I was used to the option keepspaces=true and columns=flexible in the lstlisting package but I cannot find anything similar in the minted package documentation.



Did I miss something or is it just impossible with minted ?



Here is a code sample:



documentclass{article}
usepackage{minted}

begin{document}
begin{minted}{c}
int main(int argc, char *argv)
{
extern int var;
return var;
}
end{minted}
end{document}


Compiled with: pdflatex -shell-escape sample.tex, it will produce:



code sample



But, when we copy-paste itdirectly from the PDF, we will get:



int main(int argc, char *argv)
{
extern int var;
return var;
}


You should have noticed that all the white spaces formatting has been lost in the process.



What I would like to have is a copyable code with a copy-paste selection.










share|improve this question




















  • 2




    In ConTeXt, I usually attach the source code in the pdf (using attachfile). This also avoids things such as selecting the header and footer when copy pasting directly from the pdf. I am sure there will be an equivalent method in LaTeX.
    – Aditya
    Nov 12 at 13:15










  • This is an interesting possibility, thanks for that! But, it does not provide any syntax highlight for the code. I know I want a lot, but I would like to have both! :-)
    – perror
    Nov 12 at 13:23










  • I do both. Provide syntax highlighted code for viewing on the pdf and an attached file for copy pasting. All hidden behind a macro, so that I only need to type startcode ... stopcode. It is relatively straight-forward to implement for someone who knows the innards of minted (minted saves the file to disk in order to run pygments; you just need to attach that file).
    – Aditya
    Nov 12 at 13:32












  • Well, I tried and it does not fit my need at all. I would like to have the code only once (and not having to have two ways to access it).
    – perror
    Nov 12 at 13:48










  • You can use the accsupp package to provide the actual text instead of the minted text for copying (and screen reading), but please help us help you by providing a minimal compilable code example of you setup.
    – TeXnician
    Nov 12 at 16:10

















up vote
1
down vote

favorite












I am using the minted package for syntax highlighting code in my slides, but I have some problem to make this code easily copyable directly from the PDF to the console. it seems that the whitespaces used to format the code totally disappear when we select the code on the screen.



I was used to the option keepspaces=true and columns=flexible in the lstlisting package but I cannot find anything similar in the minted package documentation.



Did I miss something or is it just impossible with minted ?



Here is a code sample:



documentclass{article}
usepackage{minted}

begin{document}
begin{minted}{c}
int main(int argc, char *argv)
{
extern int var;
return var;
}
end{minted}
end{document}


Compiled with: pdflatex -shell-escape sample.tex, it will produce:



code sample



But, when we copy-paste itdirectly from the PDF, we will get:



int main(int argc, char *argv)
{
extern int var;
return var;
}


You should have noticed that all the white spaces formatting has been lost in the process.



What I would like to have is a copyable code with a copy-paste selection.










share|improve this question




















  • 2




    In ConTeXt, I usually attach the source code in the pdf (using attachfile). This also avoids things such as selecting the header and footer when copy pasting directly from the pdf. I am sure there will be an equivalent method in LaTeX.
    – Aditya
    Nov 12 at 13:15










  • This is an interesting possibility, thanks for that! But, it does not provide any syntax highlight for the code. I know I want a lot, but I would like to have both! :-)
    – perror
    Nov 12 at 13:23










  • I do both. Provide syntax highlighted code for viewing on the pdf and an attached file for copy pasting. All hidden behind a macro, so that I only need to type startcode ... stopcode. It is relatively straight-forward to implement for someone who knows the innards of minted (minted saves the file to disk in order to run pygments; you just need to attach that file).
    – Aditya
    Nov 12 at 13:32












  • Well, I tried and it does not fit my need at all. I would like to have the code only once (and not having to have two ways to access it).
    – perror
    Nov 12 at 13:48










  • You can use the accsupp package to provide the actual text instead of the minted text for copying (and screen reading), but please help us help you by providing a minimal compilable code example of you setup.
    – TeXnician
    Nov 12 at 16:10















up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am using the minted package for syntax highlighting code in my slides, but I have some problem to make this code easily copyable directly from the PDF to the console. it seems that the whitespaces used to format the code totally disappear when we select the code on the screen.



I was used to the option keepspaces=true and columns=flexible in the lstlisting package but I cannot find anything similar in the minted package documentation.



Did I miss something or is it just impossible with minted ?



Here is a code sample:



documentclass{article}
usepackage{minted}

begin{document}
begin{minted}{c}
int main(int argc, char *argv)
{
extern int var;
return var;
}
end{minted}
end{document}


Compiled with: pdflatex -shell-escape sample.tex, it will produce:



code sample



But, when we copy-paste itdirectly from the PDF, we will get:



int main(int argc, char *argv)
{
extern int var;
return var;
}


You should have noticed that all the white spaces formatting has been lost in the process.



What I would like to have is a copyable code with a copy-paste selection.










share|improve this question















I am using the minted package for syntax highlighting code in my slides, but I have some problem to make this code easily copyable directly from the PDF to the console. it seems that the whitespaces used to format the code totally disappear when we select the code on the screen.



I was used to the option keepspaces=true and columns=flexible in the lstlisting package but I cannot find anything similar in the minted package documentation.



Did I miss something or is it just impossible with minted ?



Here is a code sample:



documentclass{article}
usepackage{minted}

begin{document}
begin{minted}{c}
int main(int argc, char *argv)
{
extern int var;
return var;
}
end{minted}
end{document}


Compiled with: pdflatex -shell-escape sample.tex, it will produce:



code sample



But, when we copy-paste itdirectly from the PDF, we will get:



int main(int argc, char *argv)
{
extern int var;
return var;
}


You should have noticed that all the white spaces formatting has been lost in the process.



What I would like to have is a copyable code with a copy-paste selection.







minted copy-paste






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 19:30

























asked Nov 12 at 10:43









perror

3711417




3711417








  • 2




    In ConTeXt, I usually attach the source code in the pdf (using attachfile). This also avoids things such as selecting the header and footer when copy pasting directly from the pdf. I am sure there will be an equivalent method in LaTeX.
    – Aditya
    Nov 12 at 13:15










  • This is an interesting possibility, thanks for that! But, it does not provide any syntax highlight for the code. I know I want a lot, but I would like to have both! :-)
    – perror
    Nov 12 at 13:23










  • I do both. Provide syntax highlighted code for viewing on the pdf and an attached file for copy pasting. All hidden behind a macro, so that I only need to type startcode ... stopcode. It is relatively straight-forward to implement for someone who knows the innards of minted (minted saves the file to disk in order to run pygments; you just need to attach that file).
    – Aditya
    Nov 12 at 13:32












  • Well, I tried and it does not fit my need at all. I would like to have the code only once (and not having to have two ways to access it).
    – perror
    Nov 12 at 13:48










  • You can use the accsupp package to provide the actual text instead of the minted text for copying (and screen reading), but please help us help you by providing a minimal compilable code example of you setup.
    – TeXnician
    Nov 12 at 16:10
















  • 2




    In ConTeXt, I usually attach the source code in the pdf (using attachfile). This also avoids things such as selecting the header and footer when copy pasting directly from the pdf. I am sure there will be an equivalent method in LaTeX.
    – Aditya
    Nov 12 at 13:15










  • This is an interesting possibility, thanks for that! But, it does not provide any syntax highlight for the code. I know I want a lot, but I would like to have both! :-)
    – perror
    Nov 12 at 13:23










  • I do both. Provide syntax highlighted code for viewing on the pdf and an attached file for copy pasting. All hidden behind a macro, so that I only need to type startcode ... stopcode. It is relatively straight-forward to implement for someone who knows the innards of minted (minted saves the file to disk in order to run pygments; you just need to attach that file).
    – Aditya
    Nov 12 at 13:32












  • Well, I tried and it does not fit my need at all. I would like to have the code only once (and not having to have two ways to access it).
    – perror
    Nov 12 at 13:48










  • You can use the accsupp package to provide the actual text instead of the minted text for copying (and screen reading), but please help us help you by providing a minimal compilable code example of you setup.
    – TeXnician
    Nov 12 at 16:10










2




2




In ConTeXt, I usually attach the source code in the pdf (using attachfile). This also avoids things such as selecting the header and footer when copy pasting directly from the pdf. I am sure there will be an equivalent method in LaTeX.
– Aditya
Nov 12 at 13:15




In ConTeXt, I usually attach the source code in the pdf (using attachfile). This also avoids things such as selecting the header and footer when copy pasting directly from the pdf. I am sure there will be an equivalent method in LaTeX.
– Aditya
Nov 12 at 13:15












This is an interesting possibility, thanks for that! But, it does not provide any syntax highlight for the code. I know I want a lot, but I would like to have both! :-)
– perror
Nov 12 at 13:23




This is an interesting possibility, thanks for that! But, it does not provide any syntax highlight for the code. I know I want a lot, but I would like to have both! :-)
– perror
Nov 12 at 13:23












I do both. Provide syntax highlighted code for viewing on the pdf and an attached file for copy pasting. All hidden behind a macro, so that I only need to type startcode ... stopcode. It is relatively straight-forward to implement for someone who knows the innards of minted (minted saves the file to disk in order to run pygments; you just need to attach that file).
– Aditya
Nov 12 at 13:32






I do both. Provide syntax highlighted code for viewing on the pdf and an attached file for copy pasting. All hidden behind a macro, so that I only need to type startcode ... stopcode. It is relatively straight-forward to implement for someone who knows the innards of minted (minted saves the file to disk in order to run pygments; you just need to attach that file).
– Aditya
Nov 12 at 13:32














Well, I tried and it does not fit my need at all. I would like to have the code only once (and not having to have two ways to access it).
– perror
Nov 12 at 13:48




Well, I tried and it does not fit my need at all. I would like to have the code only once (and not having to have two ways to access it).
– perror
Nov 12 at 13:48












You can use the accsupp package to provide the actual text instead of the minted text for copying (and screen reading), but please help us help you by providing a minimal compilable code example of you setup.
– TeXnician
Nov 12 at 16:10






You can use the accsupp package to provide the actual text instead of the minted text for copying (and screen reading), but please help us help you by providing a minimal compilable code example of you setup.
– TeXnician
Nov 12 at 16:10

















active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f459591%2fhow-to-keep-formating-when-copy-paste-code-sections-with-minted%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f459591%2fhow-to-keep-formating-when-copy-paste-code-sections-with-minted%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?