沉寂多年后,TeX 现在可以说话了!下面是几乎最少的代码!它应该会引起物理学家和宇宙学家的特别兴趣。需要安装 Adobe Reader。
\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[scaled =.92]{helvet}
\setlength{\paperwidth}{5.2075in}
\setlength{\paperheight}{4.90in}
\renewcommand*{\familydefault}{phv}
\usepackage[pdftex,margin=0.5in]{geometry}
\usepackage{soul}
\usepackage{fancyhdr}
\lhead{Sound and TeX}\chead{}
\rhead{Can you hear me?}
\lfoot{}\cfoot{}\rfoot{}
\pagestyle{fancy}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[pdftex,pdfpagelayout=SinglePage,
pdftitle={Hello world},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 Hello()
{
var cSpeaker = tts.getNthSpeakerName(0);
tts.speaker = cSpeaker;
tts.qText ("Hello, Tex Stack Exchange. Helloooo, can anybody hear me? Helloooo?");
tts.talk();
}
function HelloWorld()
{
var cSpeaker = tts.getNthSpeakerName(0);
tts.speaker = cSpeaker;
tts.qText ("Hello, Tex Stack Exchange. Helloooo, can anybody hear me?");
tts.qText("This is a new and alien TeX world.");
tts.talk();
}
function WhatsUp()
{
var cSpeaker = tts.getNthSpeakerName(0);
tts.speaker = cSpeaker;
tts.qText ("Humans are not proud of their ancestors, and rarely invite them round to dinner.");
tts.qText("What\'s up?");
tts.talk();
}
function Universe()
{
var cSpeaker = tts.getNthSpeakerName(0);
tts.speaker = cSpeaker;
tts.qText ("In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.In those days spirits were brave, the stakes were high, men were real men, women were real women and small furry creatures from Alpha Centauri were real small furry creatures from Alpha Centauri. There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable. There is another theory which states that this has already happened. I am Douglas Adams");
tts.qText("Who are you? I may be a sorry case, but I don't write jokes in base 13");
tts.talk();
}
\end{insDLJS}
%% This must be here
\OpenAction{/S/JavaScript/JS(Hello();)}
%% 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}}
\begin{document}
\phantom{0}
\begin{center}
\vspace{2cm}
\textbf{\Huge Hello World!\\[0.2cm] Can you hear me?}
\end{center}
\vfill
\newpage
\begin{Form}
\begin{center}
%% Push button is defined here
\PushButton[name=hello,%
onclick={HelloWorld();}, bordercolor={0.650 .790 .94}%
]{Hello World!}
\\[10pt]
\PushButton[name=hello,%
onclick={WhatsUp();}, bordercolor={0.650 .790 .94}%
]{What's Up?}
\\[10pt]
\PushButton[name=hello,%
onclick={Universe();}, bordercolor={0.650 .790 .94}%
]{What's with the Universe?}
\\[2cm]
\heading{Press a button!}\\
\end{center}
\end{Form}
\end{document}
更严肃地说,(所有) TeX 在“新”媒体中都有一席之地吗?
答案1
当问这样的问题时,考虑一下他们是否通过了笑声测试会有所帮助:http://river-valley.zeeba.tv/tug-2010/an-earthshaking-announcement。
更严肃地说,我认为 TeX 从定义上来说是一种排版系统。它恰好具有强大的编程能力,这使得该特定功能可以扩展到其逻辑极限,以便我们仅使用 TeX 代码就可以绘制非常复杂的图片。它还恰好被扩展用于生成 PDF 文档,而 PDF 文档(大概是通过 Adobe 的倡议)已经涵盖了许多不一定印刷的媒体。我相信(或者至少我听说,因为我不确定我是否相信)我们也可以在 TeX 文档中处理电影。那么问题似乎是,TeX 是否应该在最一般的意义上被视为 PDF 创建器,即它可以处理全部PDF 标准的规定(无论它是什么)。
我认为这是对 TeX 领域更伟大、更雄心勃勃的扩展,而不仅仅是突破其编程能力的界限。例如,假设 Javascript 被视为可接受的输出;那么在有人希望此 Javascript 与文档结构交互之前需要经过多长时间(以分钟为单位)?TeX 必须处理这个问题吗?TeX 必须成为 Javascript 解释器吗?如果将来文档通过交互式电影传递,TeX 必须创建这些电影吗?我认为它不应该。
TeX 被设计用于解决一个问题:将字母变成单词,将单词变成行,将单词变成段落,将单词变成页面,中间穿插数学运算以及各种显示或插入。为了在各种无法预料的情况下实现此任务的自动化,它提供了一种完整的(虽然有点难以理解)编程语言,该语言带有许多与其使用的排版函数相关的钩子。由于该语言是图灵完备的,因此热情的人们声称 TeX 无所不能,但事实并非如此:所讨论的任务必须能够用这种语言描述。借助钩子,这些任务包括排版,但为其他任务提供的唯一设施是:命令\special
和非常有限的输入/输出命令(尤其是\write18
)。实际上,TeX 只能通过批量导入外部实用程序来实现其他类型的编程应用程序。
我认为,试图让 TeX 做超出其设计能力的事情是错误的,试图在该设计中插入新功能也是错误的。例如,之所以hyperref
有效,是因为人们可以\special
简单地使用 向查看器提供信息,但尝试使用某种 Javascript 程序根据超链接重写文档是愚蠢的。原因是 TeX 将文档视为成品,因此甚至不考虑“运行时”操作。这对于解决排版问题是必不可少的。当然,如果您的 Javascript 对文档没有运行时影响,则可以通过 嵌入\special
,但由于这已经是可能的,我怀疑这不是问题所在。无论是实用性问题还是品味问题……我的意见已经在第一句话中给出了。