You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An often requested feature without a clear solution available in the docs / on tex.stackexchange is to be able to copy paste the code from minted code blocks in PDFs.
It seems that this is as much a limitation of how PDFs handle text as LaTeX / minted to provide this information.
So this might maybe be more about better documenting the limitations than finding an actual solution (but maybe I'm wrong and there is one that is general enough to be integrated directly into minted). It also seems to depend on the pdf viewer.
Questions about this without a clear answer are for example:
The main issues are line numbers (where a solution is to use the accsupp package to clear the alternative text) and whitespace, which there is no solution currently to make it copyable, resulting in broken formatting when pasting the code.
Example:
\documentclass{article}
\usepackage{minted}
\begin{document}
This results in a syntax error when copy/pasted:
\begin{minted}{python}
if __name__ == "__main__":
print("Hello World")
\end{minted}
\end{document}
Screenshot with text selection showing no whitespace is selected:
Result of pasting the selected text:
if __name__ == "__main__":
print("Hello World")
The text was updated successfully, but these errors were encountered:
I believe you are correct: there doesn't seem to be an existing solution for properly copying code. I can add a note in the documentation at some point.
My guess is that using attachfile or a similar package is probably the best way to approximate exact copying. But apparently even that doesn't work in some PDF viewers.
An often requested feature without a clear solution available in the docs / on tex.stackexchange is to be able to copy paste the code from minted code blocks in PDFs.
It seems that this is as much a limitation of how PDFs handle text as LaTeX / minted to provide this information.
So this might maybe be more about better documenting the limitations than finding an actual solution (but maybe I'm wrong and there is one that is general enough to be integrated directly into minted). It also seems to depend on the pdf viewer.
Questions about this without a clear answer are for example:
The main issues are line numbers (where a solution is to use the
accsupp
package to clear the alternative text) and whitespace, which there is no solution currently to make it copyable, resulting in broken formatting when pasting the code.Example:
Screenshot with text selection showing no whitespace is selected:
Result of pasting the selected text:
The text was updated successfully, but these errors were encountered: