Aad*_*hah 19 javascript pdf compilation
我想解决Project Euler 问题1:
如果我们列出10以下的所有自然数是3或5的倍数,我们得到3,5,6和9.这些倍数的总和是23.
求出1000以下3或5的所有倍数的总和.
这是我的代码:
\documentclass[10pt,a4paper]{article}
\usepackage{hyperref}
\newcommand*\rfrac[2]{{}^{#1}\!/_{#2}}
\title{Solution to Project Euler Problem 1}
\author{Aadit M Shah}
\begin{document}
\maketitle
We want to find the sum of all the multiples of 3 or 5 below 1000. We can use the formula of the $n^{th}$ triangular number\footnote{\url{http://en.wikipedia.org/wiki/Triangular_number}} to calculate the sum of all the multiples of a number $m$ below 1000. The formula of the $n^{th}$ triangular number is:
\begin{equation}
T_n = \sum_{k = 1}^n k = 1 + 2 + 3 + \ldots + n = \frac{n (n + 1)}{2}
\end{equation}
If the last multiple of $m$ below 1000 is $x$ then $n = \rfrac{x}{m}$. The sum of all the multiples of $m$ below 1000 is therefore:
\begin{equation}
m \times T_{\frac{x}{m}} = m \times \sum_{k = 1}^{\frac{x}{m}} k = \frac{x (\frac{x}{m} + 1)}{2}
\end{equation}
Thus the sum of all the multiples of 3 or 5 below 1000 is equal to:
\begin{equation}
3 \times T_{\frac{999}{3}} + 5 \times T_{\frac{995}{5}} - 15 \times T_{\frac{990}{15}} = \frac{999 \times 334 + 995 \times 200 - 990 \times 67}{2}
\end{equation}
\end{document}
我用pdflatex以下方法成功编译了它
$ pdflatex Problem1.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014/Arch Linux) (preloaded format=pdflatex)
.
.
.
Output written on Problem1.pdf (1 page, 106212 bytes).
Transcript written on Problem1.log.
它生成了以下输出PDF文件以及一堆具有可怕扩展名的其他文件:

如何运行此PDF文件以便计算解决方案?我知道问题的解决方案,但我想知道如何执行PDF文件来计算解决方案.
我之所以喜欢LaTeX而不是其他编程语言,是因为它支持文字编程,这是由DX Knuth介绍的编程方法,他是TeX的创始人,也是有史以来最伟大的计算机科学家之一.
编辑:能够在屏幕上或纸上打印计算的解决方案也很好.计算解决方案而不打印它对于加热房间很有用,但是随着夏季的开始和全球变暖,它已经很热了.此外,打印解决方案将教会我如何在LaTeX中编写一个hello world程序.
所以,今天似乎是解决这个问题的安全日子......
OP似乎并不那么PDF -savvy.然而,他显然是一个非常有文化的LaTeX家伙.这意味着,他也必须非常了解TeX,因为他是Donald Knuth的崇拜者......
对预赛来说太多了.现在为真正的肉.
首先,引用官方PDF-1.7规范文档:
PDF不是编程语言,PDF文件不是程序.
(第92页,第7.10.1节)
然而,PDF格式的PostScript的预decessor IS一个图灵完备的编程语言......图灵完备的,就如同TeX的是,创造高德纳,所有时代最伟大的计算机科学家之一.
另一方面,PostScript文件是ARE程序,并且可以由PostScript打印机轻松执行(尽管此执行时间无法提前确定).
因此,第二,OP应该能够找到一种方法将他的高级LaTeX代码转换为低级TeX代码.该代码需要发出PostScript程序,而PostScript程序又可以由PostScript打印机执行.编写TeX代码对于像OP这样的人来说应该是微不足道的,一旦给出了应该是他的TeX代码结果的PostScript代码.
我自己并不熟悉解决问题的程序的TeX方面.但是,我可以帮助PostScript.
OP的TeX代码应该生成的PostScript就是这样的(肯定有更多优化的版本可能 - 这只是第一次,快速的'射击):
%!PS
% define variables
/n1 999 def
/t1 334 def
/n2 995 def
/t2 200 def
/n3 990 def
/s1  67 def
/t3   2 def
% run the computational code
n1 t1 mul
n2 t2 mul
n3 s1 mul
sub
add
t3    div
% print result on printer, not on <stdout>
/Helvetica findfont
24 scalefont
setfont
30 500 moveto
(Result for 'Project Euler Problem No. 1' :) show 
/Helvetica-Bold findfont
48 scalefont
setfont
80 400 moveto
(                   ) cvs show 
showpage
将此PostScript代码发送到PostScript打印机,它将计算并打印解决方案.
回答其中一条评论:如果/Helvetica findfont用一个简单的print语句替换PostScript代码的最后一部分,它将无法实现您的想象.
print不会导致打印机输出纸张.相反,它要求PostScript解释器将堆栈中最顶层的项(必须是(string)!)写入标准输出通道.(如果堆栈中最顶层的项不是类型(string),则会触发typecheckPostScript错误.)
因此,将修改后的PostScript文件(print已替换我的PS代码的最后一部分)发送到打印机将不起作用(除非该打印机支持交互式executivePostScript模式 - 这不是PostScript语言的标准部分).但是,如果您将该文件提供给终端或窗口中的Ghostscript,它将起作用cmd.exe.