After rendering a document containing this code block
\begin{verbatim}
if [ ! -d .git ]; then git init; fi # Initialises a new Git repository, if doesn't already exist.
if [ ! -f README.md ]; touch README.md; fi # Creates an empty README.md file, if doesn't already exist.
git add -A # Stages any files/directories present, in preparation to commit them to local Git repo.
git commit -m 'first commit' # Commits the staged files/dirs to the local Git repo.
git remote add origin GIT_REMOTE_URL # Adds the GitHub repo created above as a "Git remote" with the alias "origin".
\end{verbatim}
to PDF using pdflatex
, and viewing the PDF in Apple's Preview application, the rendered code block looked exactly as expected:
if [ ! -d .git ]; then git init; fi # Initialises a new Git repository, if doesn't already exist.
if [ ! -f README.md ]; touch README.md; fi # Creates an empty README.md file, if doesn't already exist.
git add -A # Stages any files/directories present, in preparation to commit them to local Git repo.
git commit -m 'first commit' # Commits the staged files/dirs to the local Git repo.
git remote add origin GIT_REMOTE_URL # Adds the GitHub repo created above as a "Git remote" with the alias "origin".
However, I then tried copying and pasting the rendered code block from the PDF into a text file. I had been expecting the result to be exactly like the original, but instead it was as follows:
if[!-d.git];thengitinit;fi if [ ! -f README.md ]; touch README.md; fi git add -A git commit -m 'first commit' git remote add origin GIT_REMOTE_URL
# Initialises a # Creates an em # Stages any fi # Commits the s # Adds the GitH
Obviously, this is rather different to the original!
Using Acrobat Professional 8, the result is also wrong, but in a different way:
if [ ! -d .git ]; then git init; fi # Initialises a if [ ! -f README.md ]; touch README.md; fi # Creates an emgit add -A # Stages any figit commit -m 'first commit' # Commits the sgit remote add origin GIT_REMOTE_URL # Adds the GitHEN
My question is: is there a way to ensure that the original contents of every \begin{verbatim}...\end{verbatim}
environment is preserved in the PDF output, not only as seen by the eye but also as "seen" by the text selection tools in PDF viewing software?
accsupp
). Other issues are font encodings, mapping to Unicode (e.g. packagecmap
) and others. All of them are on-topic.