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:
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
|
show 1 more comment
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:
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
2
In ConTeXt, I usually attach the source code in the pdf (usingattachfile
). 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 typestartcode ... stopcode
. It is relatively straight-forward to implement for someone who knows the innards ofminted
(minted
saves the file to disk in order to runpygments
; 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
|
show 1 more comment
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:
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
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:
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
minted copy-paste
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 (usingattachfile
). 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 typestartcode ... stopcode
. It is relatively straight-forward to implement for someone who knows the innards ofminted
(minted
saves the file to disk in order to runpygments
; 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
|
show 1 more comment
2
In ConTeXt, I usually attach the source code in the pdf (usingattachfile
). 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 typestartcode ... stopcode
. It is relatively straight-forward to implement for someone who knows the innards ofminted
(minted
saves the file to disk in order to runpygments
; 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
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 ofminted
(minted
saves the file to disk in order to runpygments
; 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