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.

Title says it all. How do you wish "Happy New Year" to a TeXie? Compile the code below with pdfLaTeX, view it with "PDF Reader" or "Adobe Acrobat Pro" and press the "Happy New Year" button on the second page. Please suggest ways to internationalize the "Happy New Year" string by adding translations in the comments in your language.

\documentclass{scrartcl}
\setcounter{secnumdepth}{0}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{mathptmx}
\usepackage[scaled =.92]{helvet}
\usepackage{soul}
\setlength{\paperwidth}{5.2075in}
\setlength{\paperheight}{4.90in}
\renewcommand*{\familydefault}{phv}
\usepackage[pdftex,margin=0.5in]{geometry}
\usepackage{fancyhdr}
\lhead{A Sample Calculation}\chead{}
\rhead{Area of Circle}
\lfoot{}\cfoot{}\rfoot{}
\pagestyle{fancy}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[pdftex,pdfpagelayout=SinglePage,
pdftitle={Wishing you a happy year},pdfsubject={Invest your new year improving your TeX skills}%
]{hyperref}

\definecolor{background}{rgb}{0.99,0.98,0.90}
\pagecolor{background}
\setlength{\parindent}{0.0cm}
\usepackage[pdftex]{insdljs}


\begin{insDLJS}[test]{test}{JavaScript}

function doCalculation()
{
var radius=0.0 + this.getField("radius").value;
 this.getField("diameter").value=radius*2;
 this.getField("areacircle").value=  Math.PI * Math.pow(radius, 2);
}

function HappyNewYear()
{
 app.alert("Happy New Year!",3);
}


\end{insDLJS}

%% This must be here
%\OpenAction{/S/JavaScript/JS(docOpen();)}

%% Short hand commands
\newcommand{\textforlabel}[2]{%
\TextField[name={#1}, value={#2}, width=9em,align=2,%
    bordercolor={0.990 .980 .85},%
 readonly=true]{}%
}


%% Define the heading
\newcommand{\heading}[1]{\so{#1}}
\def\spacer#1{\multicolumn{2}{|c|}{}\\*[#1]}

\begin{document}
\topskip=0pt
\vphantom{-Z}
\vfill
\begin{center}
\textbf{\Huge Have a Happy New Year\\ with JavaScript\\*[4pt] and LateX!}

\end{center}
\vfill
\newpage

\begin{Form}
\begin{tabular}{|rl|}
\hline
\multicolumn{2}{|c|}{}\\*[-0.8em]\multicolumn{2}{|c|}{%
\heading{Area of Circle}}\\

%% 
%%% Input field radius

&\\*[-0.8em]\textforlabel{l01}{Radius:}&\TextField[name=radius,width=10em, bordercolor={0.650 .790 .94}]{}%
~m\\



&\\ \hline

\multicolumn{2}{|c|}{\heading{Calculate}}\\
\spacer{-0.8em}
\multicolumn{2}{|c|}{
%% Push button is defined here
\PushButton[name=start,onclick={doCalculation();},bordercolor={0.650 .790 .94}%
]{Calculate} 

%% Push button is defined here
\PushButton[name=hello,%
onclick={HappyNewYear();}, bordercolor={0.650 .790 .94}%
]{Happy New Year!} 
}\\

\spacer{-0.8em}
\hline

\multicolumn{2}{|c|}{\heading{Results}}\\

%% RESULTS
%% Diameter
\multicolumn{2}{|c|}{}\\*[-0.8em]\textforlabel{name=l04, bordercolor={0.650 0.790 0.94}}{%
Diameter :}&\TextField[name=diameter,width=10em,bordercolor={0.650 .790 .94},%
readonly=true]{}~m\\
\spacer{-0.8em}

\textforlabel{name=l05, bordercolor={0.650 0.790 0.94}}{Area:} & \TextField[name=areacircle,width=10em,%
bordercolor={0.650 .790 .94},readonly=true]{}~m$^2$\\*[-0.8em]
\spacer{1em}
\spacer{1em}
\hline
\end{tabular}
\end{Form}
\bigskip

\parindent0.5em
As proved by Archimedes, the area enclosed by a circle is $\pi$ multiplied by the radius squared \(\pi r^2\). Apollonius of Perga showed that a circle may also be defined as the set of points in a plane having a constant ratio (other than 1) of distances to two fixed foci, A and B.

Early science, particularly geometry and astrology and astronomy, was connected to the divine for most medieval scholars, and many believed that there was something intrinsically \textit{divine} or \textit{perfect} that could be found in circles. Some people still believe that the earth is still flat and is circular.


Some highlights in the history of the circle are:
\begin{enumerate}
\item 1700 BC -- The Rhind papyrus gives a method to find the area of a circular field. The result corresponds to \(\frac{256}{81}\) (3.16049\dots) as an approximate value of $\pi$.
\item 300 BC -- Book 3 of Euclid's Elements deals with the properties of circles.
In Plato's Seventh Letter there is a detailed definition and explanation of the circle. Plato explains the perfect circle, and how it is different from any drawing, words, definition or explanation.
\item 1880 -- Lindemann proves that $\pi$ is transcendental, effectively settling the millennia-old problem of squaring the circle
\item 1978 -- Donald Knuth develops \TeX\ in order to enable future generations to typeset Mathematics in a beautiful way, including all the equations that one can associate with circles.
\end{enumerate}

\end{document}
share|improve this question
    
It is interesting! All javascript libraries can work with LaTeX ? –  xport Dec 28 '10 at 17:49
    
@xport Not all. You cannot use jQuery or any of the libraries that handle the XHTML document model. Adobe has its own model, but Adobe's JS is based on ECMA so you can pretty much use any other routines you may have. Don't forget to add Happy New Year in your \language! –  Yiannis Lazarides Dec 28 '10 at 17:53
    
@Yiannis, if you have time, please show me how animation can work in pdf using Adobe ECMA javascript. –  xport Dec 28 '10 at 18:05
4  
Someone should have posted xii.tex a few days ago. –  TH. Dec 28 '10 at 18:23
1  
I tried to pdfLaTeX the above code but I get the error message: ! LaTeX Error: File `insdljs.sty' not found. I have the TeXLive 2010. Anyone getting this error message? –  yCalleecharan Jan 3 '11 at 20:54
show 13 more comments

1 Answer 1

up vote 8 down vote accepted

Yiannis,

AdobeReader comes in about 15 different languages. This is the number of possible translations of your new year's wishes. The language version of the Reader in which the PDF is opened can be accessed using the JavaScript object app.language. See:

http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/js/html/wwhelp.htm?href=JS_API_AcroJSPreface.87.1.html#1515775&accessible=true

It can be used to choose the matching greeting. I did this for French and German and some default language which appears to be the most probable one (according to the number of speakers). However, you may need to install an additional font pack ;-) :

http://www.adobe.com/support/downloads/detail.jsp?ftpID=4883

Just replace your definition of the function HappyNewYear() with the following code:

function HappyNewYear()
{
  switch(app.lang){
    case "FRA":
    hny="Bonne Ann"+String.fromCharCode(233)+"e !";break;;
    case "DE":
    hny="Gl"+String.fromCharCode(252)+"ckliches Neues Jahr!";break;;
    default:
    hny=String.fromCharCode(26032,24180,24555,20048)+"!";
  }
  app.alert(hny,3);
}

Note that some non-ascii characters had to be replaced by their Unicode representation.

Alexander

share|improve this answer
    
It's the first "e" in "Année" that should be accented... –  Seamus Jan 13 '11 at 15:24
    
@Seamus: Of course, you are right. –  AlexG Jan 13 '11 at 15:31
    
@Seamus: And as far as I know, French typography wants a space before the exclamation mark while German typography forbids it. –  AlexG Jan 13 '11 at 15:37
    
@Alexander I'm not sure about the details of typography conventions, but basic spelling I can manage... –  Seamus Jan 13 '11 at 17:35
    
@Alexander tts.qText("Thanks, and have a Happy New Year");. Default made my other half very happy:) –  Yiannis Lazarides Jan 13 '11 at 19:39
show 2 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.