2

I'm pretty inexperienced with Javascript, especially within LaTeX, so I'd like some pointers, guidance or even an MWE of my proposed "button":

I want to create a button to copy data to the system clipboard. For this I'd like to suggest using a workaround with a flash leak (don't know if it works):

function copy(str) {
   var D=document;
    if(!copy.div) { copy.div = D.createElement('div'); D.body.appendChild(copy.div);  }

flashVar = "Q1dTB3kAAAB4nKtgYI1nYOBfwMDAw8jgzPT//3975lAGBoYOdQYWhu\
SczIKk/MSiFIac1Lz0kgyG4MriktRchuLUEme41DQmBg4GGRDJ6Cc0l4l  BAibCzsDO\
CDSJgwksyRwkzuAA5AIAd7oY/w==";

copy.div.innerHTML =  '<embed src="'+flashVar+'" FlashVars="clipboard='+encodeURIComponent(str) +
    '" width="0" height="0" type="application/x-shockwave-flash"></embed>';
}

I want to use the following button which will do the copying:

\documentclass[11pt,a4paper]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shadows}

\newcommand*\button{%
  \tikz[baseline=(key.base)]
    \node[%
      draw,
      fill=white,
      drop shadow={shadow xshift=0.25ex,shadow yshift=-0.25ex,fill=black,opacity=0.75},
      rectangle,
      rounded corners=2pt,
      inner sep=1pt,
      line width=0.5pt,
      font=\scriptsize\sffamily
    ](key) {Ctrl\strut}
  ;
    \tikz[baseline=(key.base)]
    \node[%
      draw,
      fill=white,
      drop shadow={shadow xshift=0.25ex,shadow yshift=-0.25ex,fill=black,opacity=0.75},
      rectangle,
      rounded corners=2pt,
      inner sep=1pt,
      line width=0.5pt,
      font=\scriptsize\sffamily
    ](key) {C\strut}
  ;
}

\begin{document}
\button
\end{document}
1

You have already asked the same question without the code some hours ago - maybe you could have modified it instead of posting it again.

Regarding your question:

  1. Be aware that JavaScript in PDF does not work reliably. It is often disabled for security purposes and other PDF readers than Acrobat may behave different or even lack JS support.
  2. Be sure to test with the newest Acrobat version. Adobe strengthened security recently and introduced an application sandbox. Reading the clipboard should (hopefully) be off limit / impossible as this would be an information leak (for example if you copied a password in the clipboard before). Overwriting the system clipboard may be blocked too (web browsers block it, for example).
  3. A workaround may be to write the content into a form-field in the document and asking the user to copy it manually.
  • I meant to use this question as a more specific workaround solution, while the other would be LaTeX exclusive. This would allow people with the same question / functionality in mind to differentiate and choose the answer that suits their needs best. I've certainly considered all these issues with externalization of macros of this kind, but I simply see no feasible solution to this issue using LaTeX exclusively. LaTeX offers a package that does allow for copy pasting of say, listing environments, but that's not exactly what I'm looking for. @Rüdiger Voigt – 1010011010 May 1 '14 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.