LinuxSir.Org  
| 网站首页 | 注册账号 | 论坛帮助 |

欢迎来到LinuxSir.Org!
您还未登录,请登录后查看论坛,或者点击论坛上方的注册链接注册新账号。


发表新主题 回复
精华主题  
主题工具
旧 03-10-03, 11:55 第 1 帖
alphatan
 
 
 
注册会员  
  注册日期: Aug 2003
  帖子: 18
  精华: 1
 

标题: latex2pdf的脚本


由于本人学LaTeX也不久,所以有些功能可能没想到,欢迎大家对程序修改,适应各自的需要。本脚本已可以处理索引了,以后将会不断更新。

代码:
#!/bin/bash # # "latex2pdf.sh" is a script written in bash to make processing latex # file easier. # Copyright (C) 2003 alphatan<alphatan@263.net> version 0.51 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # target=${1%.tex} action=$2 declare -f dvi errorMsg ldvi lpdf lpdfmx lps lview pdf pdfmx ps view function errorMsg() { echo -e " Usage: ${0##*/} <filename> [action] " >&2 echo -e " <filename> : the tex file with '.tex' extension. " echo -e " This could not be ignored." echo -e " [action] : the 'action' you wish to operate on the '.tex' file" echo -e " dvi : process to 'dvi' output" echo -e " ps : process to 'ps' output" echo -e " pdf : process to 'pdf' output with 'dvipdf' command " echo -e " pdfmx : process to 'pdf' output with 'dvipdfmx' command " echo -e " view : view the '<filename>.pdf' with 'acroread' \n" echo -e " The action type above could put an 'l' precede it. eg. 'ldvi' " echo -e " it will call the corresponding process and do a cleaning course by " echo -e " the end. " echo -e " If the 'action' is ignored, it is refer to 'lview', it would " echo -e " cause 'lpdfmx' and 'cleaning course', and view the '.pdf' output " echo -e " with 'acroread'" } if [ ! -e ${target}.tex ]; then echo -e "ERROR!!: ${target}.tex does not exist! " >&2 errorMsg exit 1 fi function dvi() { if latex ${target}.tex ; then if [ -e ${target}.idx ] ; then if makeindex ${target}.idx ; then if latex ${target}.tex ; then return 0; else return 1 fi else return 1 fi else return 0 fi else return 1 fi } function ps() { if dvi ; then if dvips ${target}.dvi ; then return 0; else return 1 fi else return 1 fi } function pdf() { if dvi ; then if dvipdf ${target}.dvi ; then return 0; else return 1 fi else return 1 fi } function pdfmx() { if dvi ; then if dvipdfmx ${target}.dvi ; then return 0; else return 1 fi else return 1 fi } function view() { if [ -e ${target}.pdf ] ; then acroread ${target}.pdf else return 1 fi } function cleanFiles() { echo "Cleaning process caught ... " unset i; for i in aux dvi idx ilg ind lof log lot pdf ps ; do if [ ! $i = $1 ]; then if [ -e ${target}.$i ]; then rm -f ${target}.$i fi fi done unset i; } function ldvi() { if dvi ; then cleanFiles dvi else return 1 fi } function lps() { if ps ; then cleanFiles ps else return 1 fi } function lpdf() { if pdf ; then cleanFiles pdf else return 1 fi } function lpdfmx() { if pdfmx ; then cleanFiles pdf else return 1 fi } function lview() { if lpdfmx ; then if acroread ${target}.pdf ; then cleanFiles pdf return 0 else return 1 fi else return 1 fi } case $action in dvi ) eval $action ;; ps ) eval $action ;; pdf ) eval $action ;; pdfmx ) eval $action ;; view ) eval $action ;; ldvi ) eval $action ;; lps ) eval $action ;; lpdfmx ) eval $action ;; lview ) eval $action ;; '' ) eval lpdfmx ;; * ) echo -e "Error Action type! " >&2 errorMsg exit 1 ;; esac

此帖于 03-10-03 15:26 被 alphatan 编辑.
  alphatan 当前离线   回复时引用此帖
旧 03-10-03, 18:12 第 2 帖
KornLee
 
 
 
★☆★☆★☆★  
  注册日期: Nov 2002
  我的住址: LinuxWorld
  帖子: 6,960
  精华: 61
 

不错的脚本,我已经收藏到[脚本欣赏区]里啦~~谢谢
  KornLee 当前离线   回复时引用此帖
旧 03-10-05, 02:56 第 3 帖
alphatan
 
 
 
注册会员  
  注册日期: Aug 2003
  帖子: 18
  精华: 1
 

居然贴子有修改期限……
这里只好再发,因为这个脚本功能比较单独,所以以后的更新就不再加贴了。欲获得最新版可以到水木清华的TeX版或是到我的ftp的personalWorks/alphatan/latex2pdf/下载(可能经常上不了……)。

0.55
修改了dvi函数,使其可以处理cross-reference。
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;一如既往地欢迎任何意见。
代码:
#!/bin/bash # # "latex2pdf.sh" is a script written in bash to make processing latex # file easier. # Copyright (C) 2003 alphatan<alphatan@263.net> version 0.55 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # target=${1%.tex} action=$2 declare -f dvi errorMsg ldvi lpdf lpdfmx lps lview pdf pdfmx ps view function errorMsg() { echo -e " Usage: ${0##*/} <filename> [action] " >&2 echo -e " <filename> : the tex file with '.tex' extension. " echo -e " This could not be ignored." echo -e " [action] : the 'action' you wish to operate on the '.tex' file" echo -e " dvi : process to 'dvi' output" echo -e " ps : process to 'ps' output" echo -e " pdf : process to 'pdf' output with 'dvipdf' command " echo -e " pdfmx : process to 'pdf' output with 'dvipdfmx' command " echo -e " view : view the '<filename>.pdf' with 'acroread' \n" echo -e " The action type above could put an 'l' precede it. eg. 'ldvi' " echo -e " it will call the corresponding process and do a cleaning course by " echo -e " the end. " echo -e " If the 'action' is ignored, it is refer to 'lview', it would " echo -e " cause 'lpdfmx' and 'cleaning course', and view the '.pdf' output " echo -e " with 'acroread'" } if [ ! -e ${target}.tex ]; then echo -e "ERROR!!: ${target}.tex does not exist! " >&2 errorMsg exit 1 fi function dvi() { if latex ${target}.tex ; then if [ -e ${target}.idx ] ; then if makeindex ${target}.idx ; then if latex ${target}.tex ; then return 0; else return 1 fi else return 1 fi elif grep -in 'LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.' ${target}.log ; then if latex ${target}.tex ; then return 0 fi else return 1 fi } function ps() { if dvi ; then if dvips ${target}.dvi ; then return 0; else return 1 fi else return 1 fi } function pdf() { if dvi ; then if dvipdf ${target}.dvi ; then return 0; else return 1 fi else return 1 fi } function pdfmx() { if dvi ; then if dvipdfmx ${target}.dvi ; then return 0; else return 1 fi else return 1 fi } function view() { if [ -e ${target}.pdf ] ; then acroread ${target}.pdf else return 1 fi } function cleanFiles() { echo "Cleaning process caught ... " unset i; for i in aux dvi idx ilg ind lof log lot pdf ps ; do if [ ! $i = $1 ]; then if [ -e ${target}.$i ]; then rm -f ${target}.$i fi fi done unset i; } function ldvi() { if dvi ; then cleanFiles dvi else return 1 fi } function lps() { if ps ; then cleanFiles ps else return 1 fi } function lpdf() { if pdf ; then cleanFiles pdf else return 1 fi } function lpdfmx() { if pdfmx ; then cleanFiles pdf else return 1 fi } function lview() { if lpdfmx ; then if acroread ${target}.pdf ; then return 0 else return 1 fi else return 1 fi } case $action in dvi ) eval $action ;; ps ) eval $action ;; pdf ) eval $action ;; pdfmx ) eval $action ;; view ) eval $action ;; ldvi ) eval $action ;; lps ) eval $action ;; lpdfmx ) eval $action ;; lview ) eval $action ;; '' ) eval lpdfmx ;; * ) echo -e "Error Action type! " >&2 errorMsg exit 1 ;; esac
另外,对于本论坛的版面设置提点意见:
希望在“回复”的时候,不要把“清空内容”的按钮放在右下,我已经很多次把东西写完了却按了这东西,欲哭无泪,建议把它放到“标题”行的最后一列。
  alphatan 当前离线   回复时引用此帖
旧 03-10-05, 17:51 第 4 帖
minus273
 
minus273 的头像
 
 
初初初级会员  
  注册日期: Nov 2002
  我的住址: 天府之国四川 德阳
  帖子: 1,394
  精华: 7
 

用dvipdfm多好?







__________________
“不知道,反正是平白无故就进来了。”
“不可能!平白无故——那都只判十年!”
-- Aleksandr Solženicyn
minus273 est novo Sandy.
Slackware碟子搞丢了,液氦倒了……
Homepage: minus273.m-and-f.org
要不了多久,就该用了十年linux了。
  minus273 当前离线   回复时引用此帖
旧 03-10-07, 02:31 第 5 帖
alphatan
 
 
 
注册会员  
  注册日期: Aug 2003
  帖子: 18
  精华: 1
 

你说dvipdfm是在windows用的吗?对应于linux下的dvipdfmx?
如果是的话那它是个程序而已,只是管理其中一个步骤,我写这个脚本的原因是要从.tex文件到dvi ps pdf或是在输出pdf后以acroreader来查看。
不同的东西。
不过也谢谢你的意见。
引用:
最初由 Sandy 发表
用dvipdfm多好?

另外,加个latex2pdf的history. 需要源程序的话下载水木TeX版的4231贴子。
0.57
修改了运行过latex(运行正常)但没有输出的情况。
也是利用grep 在target.log文件中找‘No pages of output.'
增加了checkDVIoutput()函数,因为没有试过成功生成了.dvi却没有生成.ps,
.pdf的情况(所以不知道此情况出现时的特征),所以只在dvi()中被调用。
另外也对grep的调用去掉了-in选项而采用-q,避免输出骚扰信息。

0.56
可以处理需要多次用latex处理的文件(我暂时还没有遇到这种情况)。
增加了multiTimeLatex()函数,其在dvi()中被调用。

0.55
可以处理cross-reference了。处理了dvi()函数,用grep在target.log文件中找
‘LaTeX Warning: Label(s) may have changed. Rerun to get
cross-references right.’


0.52
由于本人学LaTeX也不久,所以有些功能可能没想到,欢迎大家对程序修改,适应
各自的需要。本脚本已可以处理索引了,以后将会不断更新。
  alphatan 当前离线   回复时引用此帖
旧 03-12-20, 22:16 第 6 帖
minus273
 
minus273 的头像
 
 
初初初级会员  
  注册日期: Nov 2002
  我的住址: 天府之国四川 德阳
  帖子: 1,394
  精华: 7
 

FT... dvipdfmx是dvipdfm的CJK-Extension
  minus273 当前离线   回复时引用此帖
发表新主题 回复


主题工具

发帖规则
您 [不可以] 发表新主题
您 [不可以] 回复主题
您 [不可以] 上传附件
您 [不可以] 编辑您的帖子

已 [启用] BB 代码
已 [启用] 表情符号
已 [启用] IMG 代码
已 [禁用] HTML 代码
[论坛跳转…]


所有时间均为[北京时间]。现在的时间是 12:57


Powered by vBulletin 版本 3.6.8
版权所有 ©2000 - 2010, Jelsoft Enterprises Ltd.
官方中文技术支持: vBulletin 中文
版权所有 ©2002 - 2009, LinuxSir.Org