Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm looking for a way to get popup references when hovering with the mouse cursor over the references in my papers. I looked around on this forum and found this question and hpesoj626's answer very useful:

Interactive PDF, Latex and Article of the Future

However, it's imperative that I can use opentype/truetype fonts in my document, including CJK. Previously, I've used XeLaTeX. I've realized that XeLaTeX is not an option for this kind of thing, since it doesn't produce PDFs in the same way. However, there is LuaLaTeX, which, as far as I understand, works similarly to pdflatex?

For my own purposes (unicode, CJK) I could just as well use LuaLaTeX (although I haven't tried this yet).

What I cannot use is simple pdflatex, which is what is used in the Perl script provided in hpesoj626's answer to the question I linked to above.

Is there a way to make this script work with unicode and opentype fonts?

share|improve this question
2  
I would try first changing my $pdflatex="pdflatex"; into my $pdflatex="lualatex"; in the Perl script. –  egreg May 2 '13 at 8:02
    
@egreg: Switching pdflatex to luatex can be done with command line argument now (the development version at bitbucket.org/robert.marik/fancytooltips), for example perl ~/path/fancy-preview filename --pdflatex="/path/lualatex" –  robert.marik.cz Aug 11 '13 at 20:10
add comment

1 Answer

Here is a non-fancytooltips solution that supports any driver, including xelatex, allowing you to use OpenType and TrueType fonts. It makes use of the macro

\tooltip[<link text colour>]{<link text>}[<tip box colour>]{<tip text>}

for generating draggable boxes in the PDF display of AdobeReader.

The macro for creating an inline citation pop-up is:

\citeTip{<bib key>}

Inside the macro, after inserting \cite{<bib key>}, a phantom "|" is passed as <link text> to the first \tooltip argument, and \fullcite{<bib key>} as <tip text> to the second \tooltip argument.

The example uses biblatex/biber. The workflow is latex->biber->latex, run on the base-name of the document source file.

Any flavour of latex can be used. Of course, the fontspec- related lines must be commented out for other drivers than xelatex or lualatex.

\documentclass[
 a4paper,12pt,
 %dvipdfmx      %uncomment this for latex->dvipdfmx
]{article}
\usepackage[sorting=none]{biblatex}

%\usepackage{fontspec}
%\setmainfont{Times New Roman}

\usepackage[T1]{fontenc} %standard fonts
\usepackage{lmodern}

\usepackage{hyperref}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% usage: \citeTip{<bib key>}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\citeTip}[1]{%
  \cite{#1}%
  \makebox[0pt][l]{%
    \tooltip[black!0]{|}{\parbox[b]{\textwidth}{\fullcite{#1}}}%
  }%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% usage: \tooltip[<link colour>]{<link text>}[<tip box colour>]{<tip text>}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{media9}
\usepackage{xcolor}
\usepackage{calc}
\usepackage{ifxetex}

\ExplSyntaxOn
\let\tpPdfLink\mix_pdflink:nn\let\tpPdfAnnot\mix_pdfannot:nnnn
\let\tpPdfXform\mix_pdfxform:n\def\tpPdfLastXform{\g_mix_pdflastxform_tl}
\ExplSyntaxOff

\newif\ifdvipdfmx
\DeclareOption{dvipdfmx}{\dvipdfmxtrue}
\ProcessOptions*\relax
\ifxetex\dvipdfmxtrue\fi

\ifpdf
  \pdfcatalog{/AcroForm<</NeedAppearances true/Fields []>>}
\else
  \ifdvipdfmx %dvipdfmx, xelatex
    \special{pdf:put
      @catalog <</AcroForm<</NeedAppearances true/Fields []>>>>
    }
  \else %dvips
    \special{ps:
      mark {Catalog} <</AcroForm<</NeedAppearances true/Fields []>>>> /PUT pdfmark
    }
  \fi
\fi

\NewDocumentCommand{\tooltip}{O{blue}mO{yellow!20}m}{{%
  \leavevmode%
  \tpPdfLink{%
    /Subtype/Screen%
    /AA<<%
      /E<</S/JavaScript/JS(%
        var fd=this.getField('tip.\thetcnt');%
        if(typeof(fdor\thetcnt)=='undefined'){%
          var fdor\thetcnt=fd.rect;var click\thetcnt=false;var dragging\thetcnt=false;%
        }%
        if(fd.display==display.hidden){%
          fd.delay=true;fd.display=display.visible;fd.delay=false;%
        }%
        this.dirty=false;%
      )>>%
      /X<</S/JavaScript/JS(%
        if(!dragging\thetcnt){
          if(click\thetcnt==false){fd.display=display.hidden;}%
          click\thetcnt=false;this.dirty=false;%
        }
      )>>%
      /U<</S/JavaScript/JS(click\thetcnt=true;this.dirty=false;)>>%
      /PC<</S/JavaScript/JS (%
        var fd=this.getField('tip.\thetcnt');%
        try{fd.rect=fdor\thetcnt;}catch(e){}%
        fd.display=display.hidden;this.dirty=false;%
      )>>%
    >>%
  }{{\color{#1}#2}}%
  \sbox\tiptext{\fcolorbox{black}{#3}{#4}}%
  \edef\twd{\the\wd\tiptext}%
  \edef\tht{\the\ht\tiptext}%
  \edef\tdp{\the\dp\tiptext}%
  \tpPdfXform{\tiptext}%
  \raisebox{\heightof{#2}}[0pt][0pt]{\makebox[0pt][l]{%
    \tpPdfAnnot{\twd}{\tht}{\tdp}{%
      /Subtype/Widget/FT/Btn/Ff 65536/T (tip.\thetcnt)/F 3%
      /MK<</TP 1/I \tpPdfLastXform/IF<</S/A/FB true/A [0.0 0.0]>>>>%
      /AA <<%
        /U <<%
          /S/JavaScript/JS(%
            var fd=event.target;%
            var mX=this.mouseX;var mY=this.mouseY;%
            var drag=function(){%
              var nX=this.mouseX;var nY=this.mouseY;%
              var dX=nX-mX;var dY=nY-mY;%
              var fdr=fd.rect;%
              fdr[0]+=dX;fdr[1]+=dY;fdr[2]+=dX;fdr[3]+=dY;%
              fd.rect=fdr;mX=nX;mY=nY;%
            };%
            if(!dragging\thetcnt){%
              dragging\thetcnt=true;Int=app.setInterval("drag()",1);%
            }%
            else{app.clearInterval(Int);dragging\thetcnt=false;}%
            this.dirty=false;%
          )%
        >>%
      >>%
    }%
  }}%
  \stepcounter{tcnt}%
}}
\newsavebox\tiptext\newcounter{tcnt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{filecontents*}{my.bib}
@article{einstein05,
    author={Albert Einstein},
    title="Zur Elektrodynamik bewegter K{\"o}rper",
    journal={Annalen der Physik und Chemie},
    volume={17},
    year={1905},
    pages={891--921}
}

@article{einstein15,
    author={Albert Einstein},
    title="Die Grundlage der allgemeinen Relativit{\"a}tstheorie",
    journal={Annalen der Physik},
    volume={354},
    year={1916},
    pages={769--822}
}
\end{filecontents*}

\addbibresource{my.bib}
\begin{document}
The principles of the Special Relativity Theory were first published in
1905\citeTip{einstein05}. Einstein coined the term `Special Relativity
Theory' while working on the General Relativity Theory, published in
1916\citeTip{einstein15}.
\printbibliography
\end{document}

enter image description here

share|improve this answer
    
That works beautifully and it's exactly what I wanted. I just have two questions/problems: 1) When I open the document in a reader other than Adobe Acrobat/Reader, that lack support for popups, all the pop-ups are displayed by default, as opposed to being concealed by default. This makes the document unreadable. Is there any way to make them concealed by default instead? My second question is 2) is it possible to make all the biblatex citation commands (e.g. \cite, \parencite, \headlesscite etc) function like \citeTip by default? This would also enable me to use a different citation style. –  Mårten May 2 '13 at 13:49
1  
@Mårten: Currently only AdobeReader supports this feature. I could simplify the code to not use JavaScript. But still AR is required. –  AlexG May 2 '13 at 14:23
    
Yes I understand that, but when I used the example that was linked to in my original question, I could read the document without the popups in other readers, whereas with this one, the popups appear as open in the document when read in other readers, meaning it cannot be read using those readers at all (as opposed to simply being read as traditional PDFs with no popups). Do you see what I mean? –  Mårten May 2 '13 at 14:25
    
@Mårten: For the other citing commands, copy the code of the \newcommand\citeTip... command, and replace \cite by \parencite etc. –  AlexG May 2 '13 at 14:25
1  
@Mårten: Weird. In Linux AR-9 and Windows AR-10, I can close the tips by wiping across the links again. And they don't ask for saving nor do they tacitly save. At least saving can be suppressed. See my edit. –  AlexG May 7 '13 at 7:04
show 10 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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