I have three related issues here and I wonder, which approaches/libraries/built-in utilities may help me achieve the following:
First
There are many programming languages and file formats which depend on proper indentation, Python and Yaml being the most prominent examples. I would like to embed copy-pasteable leading spaces.
I've checked the following questions to see if I can render copypaste-able spaces:
- Viewer-independent copyable spaces at the beginning of a line? - the solution does not work in adobe acrobat
- How to keep indentations in Python code copied from LaTeX PDF? - the solution should work in both acrobat and chrome pdf viewer (and many other), but the following snippet does not work, at least on Overleaf (Link to snippet) with pdfLaTeX 2021:
\documentclass{article}\usepackage{transparent}\begin{document}\showoutput\makeatletter\def\@xobeysp{\leavevmode\nobreak\texttransparent{0}{\char32}}\makeatother\begin{verbatim}for row in range(1,9): for col in range(1,9): print(int(str(row)+str(col)))\end{verbatim}\end{document}
produces
for␣row␣in␣range(1,9):␣␣␣␣for␣col␣in␣range(1,9):␣␣␣␣␣␣␣␣print(int(str(row)+str(col)))
on copy-paste
Second
I would like to render whitespace (spaces) in a form of a small opaque dots. An example of what I am trying to do could be easily explained visually, see Prism.js Plugin called "Show Invisibles"
Third
I would like to provide the possibility to select the whitespace redndered with the dot but instead of dot a person gets proper whitespace in the buffer.
Most programming books do not allow user to copy-paste the contents of a code snippet with the whitespace preserved. It is rather painful to then reindent the paste. Is there a possibility to embed selectable whitespace under the dots, so when a person selects and copies the dots, the actual copy contains not the dots but the spaces?
Thanks in advance!