Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support copy pasting code keeping formatting intact #302

Closed
maxnoe opened this issue May 18, 2021 · 1 comment
Closed

Support copy pasting code keeping formatting intact #302

maxnoe opened this issue May 18, 2021 · 1 comment
Labels

Comments

@maxnoe
Copy link

maxnoe commented May 18, 2021

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:

Screenshot_20210518_124110

Result of pasting the selected text:

if __name__ == "__main__":
print("Hello World")
@gpoore
Copy link
Owner

gpoore commented May 18, 2021

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.

@gpoore gpoore added the docs label May 18, 2021
@gpoore gpoore closed this as completed in 901c003 Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants