6

I'm adding a title clock in the foot line of a beamer slide, if I compile it with pdfLaTeX it works fine; while the clock doesn't align in the middle vertically if compiling with XeLaTeX. How can I fix this.

Here is my MWE:

\documentclass[10pt]{beamer}
\usepackage[font=Times,timeinterval=1]{tdclock}
\usetheme{Madrid}
\title{Title}
\author{Authors}
\institute{Institute}
\date[\initclock\tddate\ \ \tdtime]{\today}
\begin{document}
\frame{\titlepage}
\end{document}
  • Note that this is not beamer-specific: you'll see it with any class. I think it's linked to the (x)dvipdfm(x) driver family, as the docs warn that tdclock only works with PDF mode/dvips. – Joseph Wright Dec 25 '14 at 20:40
3

Quote from the tdclock documentation:

The package requires hyperref, xkeyval and xcolor packages. It works with PDFLATEX as well as with LATEX→DviPs→Ps2pdf sequence. In documents generated by Dvipdfm, the clock does not work properly.


In case you are using xelatex for special fonts not available with pdflatex, tdclock also seems to work fine with lualatex which also lets you use special fonts.

2

Maybe tdclock and xelatex are not compatible. I try to change the packet itself and it's my temporary solution.

In file tdclock.sty, change the \def of \clockfield and \pdfcolon may fix this problem for xelatex.

I just make box bigger.

old:

\def\pdfcolon{%
\clock@setfonsize\clock@setheight\clock@setfontcolor%\clock@setwidth
\setbox\sizebox=\hbox{\TextField[readonly=true, name=separatortime, width=0.90\clock@fontsize, height=\clock@height, align = 0, color =\clock@fontcolor, charsize = \clock@fontsize,value=:]{}}%
\vrule width 0pt height 2pt\kern-0.4pt\kern-\wd\sizebox\kern 0.90\clock@fontsize{\raisebox{-\b@h\clock@fontsize}{\raisebox{-\a@h pt}%
{\mbox{\TextField[name=separatortime, width=0.90\clock@fontsize, height=\clock@height, align = 0, color =\clock@fontcolor, charsize = \clock@fontsize,
readonly=true,value=:]{}\kern-0.90\clock@fontsize\kern\a@one pt\kern \b@one\clock@fontsize\vrule width 0pt height 2pt}}}}%
}

\def\clockfield#1{%
\clock@setfonsize\clock@setheight\clock@setfontcolor%\clock@setwidth
\setbox\sizebox=\hbox{\TextField[readonly=true, name=#1, width=1.31\clock@fontsize, height=\clock@height, align = 0, color =\clock@fontcolor, charsize = \clock@fontsize]{}}%
\vrule width 0pt height 2pt\kern-\a@a pt\kern-\wd\sizebox\kern 1.31\clock@fontsize{\raisebox{-\b@h\clock@fontsize}%
{\raisebox{-\a@h pt}{\mbox{\TextField[name=#1, width=1.31\clock@fontsize, height=\clock@height, align = 0, color =\clock@fontcolor, charsize = \clock@fontsize,readonly=true,
value={}]{}\kern-1.31\clock@fontsize\kern\a@a pt\kern \b@b\clock@fontsize\vrule width 0pt height 2pt}}}}%
}

new:

\def\pdfcolon{%
\clock@setfonsize\clock@setheight\clock@setfontcolor%\clock@setwidth
\setbox\sizebox=\hbox{\TextField[readonly=true, name=separatortime, width=0.90\clock@fontsize, height=1.2\clock@height, align = 0, color =\clock@fontcolor, charsize = \clock@fontsize,value=:]{}}%
\vrule width 0pt height 2pt\kern-0.4pt\kern-\wd\sizebox\kern 0.90\clock@fontsize{\raisebox{-\b@h\clock@fontsize}{\raisebox{-\a@h pt}%
{\mbox{\TextField[name=separatortime, width=0.90\clock@fontsize, height=1.2\clock@height, align = 0, color =\clock@fontcolor, charsize = \clock@fontsize,
readonly=true,value=:]{}\kern-0.90\clock@fontsize\kern\a@one pt\kern \b@one\clock@fontsize\vrule width 0pt height 2pt}}}}%
}

\def\clockfield#1{%
\clock@setfonsize\clock@setheight\clock@setfontcolor%\clock@setwidth
\setbox\sizebox=\hbox{\TextField[readonly=true, name=#1, width=1.6\clock@fontsize, height=1.2\clock@height, align = 0, color =\clock@fontcolor, charsize = \clock@fontsize]{}}%
\vrule width 0pt height 2pt\kern-\a@a pt\kern-\wd\sizebox\kern 1.6\clock@fontsize{\raisebox{-\b@h\clock@fontsize}%
{\raisebox{-\a@h pt}{\mbox{\TextField[name=#1, width=1.6\clock@fontsize, height=1.2\clock@height, align = 0, color =\clock@fontcolor, charsize = \clock@fontsize,readonly=true,
value={}]{}\kern-1.6\clock@fontsize\kern\a@a pt\kern \b@b\clock@fontsize\vrule width 0pt height 2pt}}}}%
}

enter image description here

1

The tdclock implementation is overly complicated and error-prone.

Here is an alternative implementation that works properly with all TeX engines and back-ends:

\documentclass{beamer}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Digital Clock Implementation
%
% Usage:
%
%   % set-up (defaults)
%   \def\clockfont{Helvetica} % or Times
%   \def\clockfontscale{0.93}
%   \def\clockformat{yyyy/mm/dd HH:MM:ss}
%   \def\clockrefresh{1000} % milli-seconds
%
%   % insert clock
%   \digiclock
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{pdfbase}
\ExplSyntaxOn
\let\clockPdfAnnot\pbs_pdfannot:nnnn\let\clockPdfLastAnn\pbs_pdflastann:
\let\clockAppendToFields\pbs_appendtofields:n
\ExplSyntaxOff

\makeatletter
\def\clock@start#1#2#3{%
  function showtime#3(){%
    this.getField("digiclock.#3").value=util.printd("#1",new Date());%
    this.dirty=false;%
  }%
  showtime#3();%
  var digiclock#3=app.setInterval("showtime#3()",#2);%
}%
\newcounter{clock@num}%
\newlength\ex@height%
\newlength\clock@width%
\newlength\clock@height%
\def\digiclock{%
  \settowidth\clock@width{\clockformat}%
  \settoheight\clock@height{\clockformat}%
  \settoheight\ex@height{X}%
  \extractcolorspec{.}\clock@tempb% current color (\setcolor{...})
  \expandafter\convertcolorspec\clock@tempb{rgb}\clock@tempb%
  \edef\clock@tempa{\expandafter\clock@rgbcomp\clock@tempb\@nil}%
  \raisebox{\depth}{%
    \makebox[\clockfontscale\clock@width][l]{%
      \clockPdfAnnot{\clockfontscale\clock@width}%
                    {\clockfontscale\clock@height}{\clockfontscale\clock@height}{%
        /Subtype/Widget/FT/Tx/T (digiclock.\theclock@num) /Ff 1
        /DA (/\clockfont\space 0 Tf \clock@tempa\space rg)
        /MK<</BC []/BG []>>
        /Q 2
        /BS <</W 1/S/S>>
        /AA <<
          /PO <</S/JavaScript/JS(\clock@start{\clockformat}{\clockrefresh}{\theclock@num})>>
          /PC <</S/JavaScript/JS(app.clearInterval(digiclock\theclock@num);)>>
        >>
      }%
    }%
    \vrule width 0pt height 0.5\ex@height depth 0.5\ex@height%
  }%
  \clockAppendToFields{\clockPdfLastAnn}%
  \stepcounter{clock@num}%
}
\def\clock@rgbcomp#1,#2,#3\@nil{#1 #2 #3}
\makeatother
%default settings
\def\clockfont{Helvetica}
\def\clockfontscale{0.93}
\def\clockformat{yyyy/mm/dd HH:MM:ss}
\def\clockrefresh{1000}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\usetheme{Madrid}
\date[\def\clockfontscale{1.1}\def\clockformat{HH:MM:ss}\digiclock]{\today}

\begin{document}

\begin{frame}
  \LARGE current date \& time: \digiclock
\end{frame}

\end{document}

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.