penn

链接

使用Make管理LaTeX文件

2008年12月20日 18:08 | Comments(0) | Category:LaTeX | Tags:

 TEX := xetex

MP := mpost

vpath %.mp pic

fig=$(patsubst %.mp, %.eps,  $(wildcard figures/*.eps))
texTmp=$(filter-out main.tex, $(wildcard main.*));

all:$(fig)
        $TEX main.tex
       
%.eps:%.mp

        $MP $^ -o $@

clean:
        -rm -f $(fig)
        -rm -f $(texTmp)

A perl script for generating eps files from mp codes

2008年11月14日 22:12 | Comments(0) | Category:Metapost | Tags:

I am indebted to instanton and cvgmt at CTeX forum who provided the source codes, you can find the web here

#!/usr/bin/perl

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# mp2eps version 1.0 : produce postscript. files from metapost sources   #
# Copyright (C) 2004 Glad Deschrijver, Wed Jun 16 2004, Wed Oct 06 2004 #
# [email]Glad.Deschrijver@UGent.be[/email]                                             #
#                                                                       #
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, #
# USA.                                                                  #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

use File::Spec::Functions;
use File::Basename;
use File::Find;
use File::Copy;

$delete = "yes";
$preview = "no";
$previewcmd = "gsview32";
$rename = "yes";
$standalone = "yes";
$typeset = "latex";

$progname = "$0";
$version = "1.0";
$copyright = "Copyright (C) 2004 Glad Deschrijver";
$file = "";
$extension = 1;
$mp2epstmp = "_mp2eps_";

sub usage
{
       
print <<EOF;
Usage: $progname [OPTIONS] file[.mp]
Options: [defaults in brackets after descriptions]
Configuration:
  --typeset=CMD                        use CMD for typesetting [$typeset]
  --standalone=yes/
no                produce standalone EPS figures [$standalone]
  -
s                                short for --standalone=yes
  --
delete=yes/no                delete auxiliary files produced by mpost
                                [$delete]
  --
rename=yes/no                rename outputfiles to name mentioned in
                                file.mp as e.g.
                                % <figure number="1" name="testfig.eps"/>
  --preview=yes/
no                preview using program defined
                                by --previewcommand [$preview]
  -p                                short for --preview=yes
  --previewcommand=CMD                use CMD to preview the output file [$previewcmd]
  -h, --help                        display this help and
exit
  -v, --version                        output version information and
exit
EOF
}

sub parsefilename
{
        if ($file eq "")
        {
               
print "$progname: At least one file name is required as an argument.\n";
               
exit 1;
        }
        else
        {
                $F = $file;
                $F =~
s/\.[^\.]*$//;
                $ext = $file;
                $ext =~
s/.*\.//g;
                if ($ext eq "mp")
                {
                        $file = $F;
                }
                if (! -r "$file.mp")
                {
                       
print "$progname: $file.mp not found or not readable.";
                       
exit 1;
                }
        }
        $path = dirname("$file.mp");
        $file = basename("$file.mp");
        $file =~
s/\.mp$//;
       
chdir($path);
}

sub createtexfile
{
        $tmpfile2 = "${tmpfile}.tex";
       
open(F, ">$tmpfile2");
       
print F "\\documentclass\{report\}\n";
       
print F "\\usepackage\{amssymb\}\n";
       
print F "\\usepackage\{amsmath\}\n";
       
print F "\\usepackage\{times,mathptmx\}\n";
       
print F "\\usepackage\{graphicx\}\n";
       
print F "\\usepackage\{color\}\n";
       
print F "\\begin\{document\}\n";
       
print F "\\pagestyle\{empty\}\n";
       
print F "\\includegraphics\{$file.$extension\}\n";
       
print F "\\end\{document\}";
       
close(F);
}

sub removewanted
{
        /^$tmpfile/ &&
unlink($File::Find::name);
}

sub typesetfile
{
        $tmpfile = "${file}${mp2epstmp}";
       
system("mpto -tex \"$file.mp\" > \"${tmpfile}.tex\"");
        find(\&removewanted, curdir());
       
system("mpost \"$file.mp\"");

       
open(F, "<$file.mp");
        @filecontents = <F>;
       
close(F);
        $i = 0;
        foreach $fileline (@filecontents)
        {
                if ($fileline =~ /^beginfig/)
                {
                        $fileline =~
s/.*\(//;
                        $fileline =~
s/\).*//;
                       
chop($fileline);
                        $fignums[$i++] = $fileline;
                }
        }
       
undef @filecontents;
        for ($i = 0; $i < @fignums; $i++)
        {
                $extension = $fignums[$i];
                $file2 = "${file}_${extension}";
                if ($standalone eq "yes")
                {
                        createtexfile();
                       
system("latex $tmpfile");
                       
system("dvips -E ${tmpfile}.dvi -o ${tmpfile}.eps");
                       
open(F, "<${tmpfile}.eps");
                        @tmpfilecontents = <F>;
                       
close(F);
                       
open(F, ">${file2}.eps");
                        foreach $tmpfileline (@tmpfilecontents)
                        {
                                $tmpfileline =~
s/$tmpfile\.eps/\"${file2}.eps\"/g;
                                $tmpfileline =~ s/$tmpfile\.dvi/\"${file2}.dvi\"/g;
                                print F $tmpfileline;
                        }
                        close(F);
                        undef @tmpfilecontents;
                        find(\&removewanted, curdir());
                }
                else
                {
                        move("
${file}.${extension}", "${file2}.eps");
                }
                if ($preview eq "
yes")
                {
                        system("
$previewcmd $file2.eps");
                }
        }
}

sub deleteauxfiles
{
        unlink("
${file}.mpx");
        unlink("
${file}.
log");
        for ($i = 0; $i < @fignums; $i++)
        {
                unlink("
${file}.$fignums[$i]");
        }
        if ($rename eq "
yes")
        {
                for ($i = 0; $i < @fignums2; $i++)
                {
                        unlink("
${file}_$fignums2[$i].eps");
                }
        }
        unlink("
mptextmp.mp");
        unlink("
mptextmp.mpx");
}

sub renameoutputfiles
{
        open(F, "
<${file}.mp");
        @filecontents = <F>;
        close(F);
        $i = 0;
        foreach $fileline (@filecontents)
        {
                if ($fileline =~ /\%.* <figure\ .*>/)
                {
                        $filenum = $fileline;
                        $filename = $fileline;
                        $filenum =~ s/.*number=\"([^\"]*)\".*/\1/;
                        $filename =~ s/.*name=\"([^\"]*)\".*/\1/;
                        chop($filenum);
                        chop($filename);
                        $fignums2[$i++] = $filenum;
                        $filename =~ s/\.(eps|ps)$//;
                        $tmpfile = "
${file}_$i";
                        open(F, "
<${tmpfile}.eps");
                        @tmpfilecontents = <F>;
                        close(F);
                        open(F, "
>${filename}.eps");
                        foreach $tmpfileline (@tmpfilecontents)
                        {
                                $tmpfileline =~ s/$tmpfile\.eps/${filename}.eps/g;
                                $tmpfileline =~ s/$tmpfile\.dvi/${filename}.dvi/g;
                                print F $tmpfileline;
                        }
                        close(F);
                        undef @tmpfilecontents;
                }
        }
        undef @filecontents;
}

foreach $arg (@ARGV)
{
        if ($arg eq "
-h" || $arg eq "--help")
        {
                usage();
                exit 0;
        }
        elsif ($arg =~ /^--preview=/)
        {
                $preview = $arg;
                $preview =~ s/^--preview=//;
        }
        elsif ($arg eq "
-p")
        {
                $preview = "
yes";
        }
        elsif ($arg =~ /^--standalone=/)
        {
                $standalone = $arg;
                $standalone =~ s/^--standalone=//;
        }
        elsif ($arg eq "
-s")
        {
                $standalone = "
yes";
        }
        elsif ($arg =~ /^--rename=/)
        {
                $rename = $arg;
                $rename =~ s/^--rename=//;
        }
        elsif ($arg =~ /^--typeset=/)
        {
                $typeset = $arg;
                $typeset =~ s/^--typeset=//;
        }
        elsif ($arg eq "
-v" || $arg eq "--version")
        {
                print "
$progname $version\n";
                print "
$copyright\n";
                print "
This program comes with ABSOLUTELY NO WARRANTY.  This is free\n";
                print "
software, and you are welcome to redistribute it under\n";
                print "
the terms of the GNU General Public License.\n";
                exit 0;
        }
        elsif ($arg =~ /^-/)
        {
                usage();
                exit 1;
        }
        else
        {
                $file = $arg;
        }
}

parsefilename;
typesetfile;
if ($rename eq "
yes")
{
        renameoutputfiles;
}
if ($delete eq "
yes")
{
        deleteauxfiles;
}

After saved the file, you should change the attribute of the file as an executive program.

$ chmod +x mp.pl
and then, you can move the file to /usr/local/bin or $HOME/bin for using.

Backup and recover your boot sector

2008年11月14日 21:36 | Comments(0) | Category:Linux | Tags:

You can can use rsync for remote backups and tar or dd for local backups to backup your file system, however, there aren't as many options for backuping the boot sector.  But,  having a backup of your boot sector is equally important in the events of system crash.  Fortunately, dd tool does this work perfectly.

Grub and Lilo, or any other boot loader, generally installed ot the boot sector of your boot disc. After you have installed or modified your boot sector and verified that whether it works, back it up by writting it to a file on your hard driver:

for IDE driver:

# dd if=/dev/hda of=bootsector.bin bs=512 count=1

for SCSI driver:

# dd if=/dev/sda of=bootsector.bin bs=512 count=1

or you can write it to a floppy disk directly:

# dd if=/dev/hda of=/dev/fd0 bs=512 count=1

Make sure that you use the right source and destination, if you mistakely write the a file or the floppy to your boot driver when you make a backup, you'll damage your boot sector and won't enable to boot.

Now, if there has any error on your boot sector, you can restore rapidly from these images backuped previously by reversing the "if" and "of" destination:

# dd if=bootsector.bin of=/dev/hda

if it stored on a floppy disk, use following command:

# dd if=/dev/fd1 of=/dev/hda

relatively, if the driver is a SCSI disk, substitute sda for hda.

Gentoo中文UTF-8设置及美化

2008年11月05日 19:34 | Comments(2) | Category:Linux | Tags:

原帖在这里,为简化期间,只贴出简略的步骤和配置文件。

一、安装基本系统
依照Gentoo的安装手册进行安装,安装手册的地址点击这里。我选择的是AMD64。这里要非常感谢gentoo中文文档组的成员。由于我的硬盘没有光驱,所以在安装的时候需要从老的linux系统启动,然后使用chroot命令切换到新的系统下。下面使我的硬盘使用情况:
/dev/hda --- 原来老的linux系统(因为硬盘摔了一下,经常丢东西,所以要重装系统)。
/dev/hdc --- 目前要安装的linux所在硬盘。
/dev/sda --- 我的SATA硬盘,安装的是MS XP系统。

这是我的/etc/make.conf和/etc/locale.gen文件

代码:

# These settings were set by the catalyst build script that automatically built this stage
# Please consult /etc/make.conf.example for a more detailed example
CFLAGS="-march=athlon64 -O3 -pipe -ftracer -funit-at-a-time -fforce-addr -fpeel-loops -funswitch-loops"
CHOST="x86_64-pc-linux-gnu"
LDFLAGS="-Wl,-O1 -Wl,--enable-new-dtags -Wl,--sort-common -Wl,--strip-all"
CXXFLAGS="${CFLAGS} -fvisibility-inlines-hidden"
CBUILD="x86_64-pc-linux-gnu"
MAKEOPTS="-j2"
ACCEPT_KEYWORDS="amd64"
GENTOO_MIRRORS="http://61.135.158.199 ftp://ftp.sjtu.edu.cn/sites/gentoo ftp://gg3.net/pub/linux/gentoo"
SYNC="rsync://61.135.158.199/gentoo-portage"

#
# USE
USE="-midi -ipv6 -doc svga linguas_zh_CN fbcon 3dnow aac font-server bash-completion amd64 X lcms mmx sse gtk gtk2 -gnome nls -qt -kde alsa -cups cjk -dvd -dvdr -debug aalib jpeg wmf mng svg png mpeg truetype opengl stroke -xinerama -joysticks readline lm_sensors quicktime xv xvid bzip2 acc ftp python xml libcaca xvmc nvidia unicode -no-old-linux tiff symlink encode gif sdl imlib chardet mp3 wma real srt msn qq preview-latex fontconfig xpm a52 -emacs -xemacs -latex ggi gd pdf plotutils -berkdb"

#
# Other
AUTOCLEAN=yes
LINGUAS="zh_CN"
LANG="zh_CN"
#DISDIR=
#FEATURES="ccache confcache"
CCACHE_SIZE="2G"
CCACHE_DIR="/var/tmp/cache"
VIDEO_CARDS="nvidia"
ALSA_CARDS="intel8x0"   
#PORTDIR_OVERLAY=/usr/local/portage
source /usr/portage/local/layman/make.conf
INPUT_DEVICES="mouse keyboard"
#/etc/locale.gen
en_US ISO-8859-1
en_US.UTF-8 UTF-8
zh_CN GB2312
zh_CN.GBK GBK
zh_CN.GB18030 GB18030
zh_CN.UTF-8 UTF-8
zh_HK BIG5-HKSCS
zh_HK.UTF-8 UTF-8
zh_TW BIG5
zh_TW.UTF-8 UTF-8

调整/boot/grub/grub.conf文件

代码:
default 0
timeout 30
#splashimage=(hd0,0)/boot/grub/self1.xpm.gz
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
# /dev/hda的老linux系统
title Gentoo Linux (HDA)
root    (hd0,0)
kernel  /kernel-2.6.16-gentoo-r7 root=/dev/hda6 video=vesafb:1024x768@75,mtrr,ywrap vga=0x318 splash=silent,fadein,theme:sexy CONSOLE=/dev/tty1
initrd /fbsplash-penn

# 新安装的Gentoo系统。
title Gentoo Linux (HDC)
root    (hd1,0)
kernel  /kernel-2.6.23-gentoo-r3 root=/dev/hdc6 video=vesafb:1024x768@75,mtrr,ywrap vga=0x318

#这里为XP的启动提供通道
title Window XP
map (hd0) (hd2)
map (hd2) (hd0)
rootnoverify (hd2,0)
makeactive
chainloader +1
安装完基本系统,安装X和fvwm. 这里就简单的emerge就行了。此处不在多说。
二、安装字体和字体设置。
1. 增加字体
使用emerge安装的字体:
代码:
emerge  media-fonts/corefonts wqy-bitmapfont media-fonts/wqy-zenhei media-fonts/ttf-bitstream-vera
现在开始盗版了,我是把window的字体拷贝到
/usr/share/font/local目录下.
我拷贝的字体有:SimSun-Bold.ttf,SimSun-BoldItalic.ttf,SimSun-Italic.ttf,mingliu.ttc,msyh.ttf,msyhbd.ttf,tahoma.ttf,tahomabd.ttf等。
2. 设置x核心字体
代码:
# cd /usr/share/fonts/local
# ttmkfdir
# cp fonts.scale fonts.dir
如果没有ttmkfdir工具的朋友需要
代码:
# emerge x11-apps/ttmkfdir
在/etc/X11/xorg.conf里面添加字体路径:
代码:
    FontPath    "/usr/share/fonts/corefonts/"
    FontPath    "/usr/share/fonts/local/"
    FontPath    "/usr/share/fonts/ttf-bitstream-vera/"
    FontPath    "/usr/share/fonts/wqy-bitmapfont"
    FontPath    "/usr/share/fonts/wqy-zenhei/"
3. 设置XFT字体
应为/usr/share/fonts是xft自动搜索目录,所以不需要另外设置,只需要修改好fontconfig文件即可。下面是草兄的配置,放到/etc/fonts/local.conf,不建议直接编辑/etc/font.conf文件
代码:
<?xml version="1.0"?>
<fontconfig>
        <alias>
                <family>serif</family>
                <prefer>
                        <family>Bitstream Vera Serif</family>
                        <family>Microsoft Yahei</family>
                        <family>DejaVu Serif</family>
                        <family>AR PL ShanHeiSun Uni</family>
                        <family>WenQuanYi Bitmap Song</family>
                        <family>AR PL ZenKai Uni</family>
                </prefer>
        </alias>
        <alias>
                <family>sans-serif</family>
                <prefer>
                        <family>Bitstream Vera Sans</family>
                        <family>Microsoft Yahei</family>
                        <family>DejaVu Sans</family>
                        <family>AR PL ShanHeiSun Uni</family>
                        <family>WenQuanYi Bitmap Song</family>
                        <family>AR PL ZenKai Uni</family>
                </prefer>
        </alias>
        <alias>
                <family>monospace</family>
                <prefer>
                        <family>Bitstream Vera Sans Mono</family>
                        <family>Microsoft Yahei</family>
                        <family>DejaVu Sans Mono</family>
                        <family>AR PL ShanHeiSun Uni</family>
                        <family>WenQuanYi Bitmap Song</family>
                        <family>AR PL ZenKai Uni</family>
                </prefer>
        </alias>
        <match target="font" >
                <edit name="rgba" mode="assign">
                        <const>none</const>
                </edit>
                <edit mode="assign" name="antialias" >
                        <bool>true</bool>
                </edit>
                <edit mode="assign" name="autohint" >
                        <bool>false</bool>
                </edit>
                <edit name="hinting">
                        <bool>true</bool>
                </edit>
                <edit name="hintstyle" mode="assign" >
                        <const>hintmedium</const>
                </edit>
        </match>
        <match target="font" >
                <test name="family" compare="contains" >
                        <string>Song</string>
                        <string>Sun</string>
                        <string>Kai</string>
                        <string>Ming</string>
                </test>
                <test name="weight" compare="less_eq">
                        <int>100</int>
                </test>
                <test compare="more_eq" target="pattern" name="weight" >
                        <int>180</int>
                </test>
                <edit mode="assign" name="embolden" >
                        <bool>true</bool>
                </edit>
        </match>
        <match target="font" >
                <test name="family" compare="contains" >
                        <string>Song</string>
                        <string>Sun</string>
                        <string>Kai</string>
                        <string>Ming</string>
                </test>
                <edit name="globaladvance">
                        <bool>false</bool>
                </edit>
                <edit name="spacing">
                        <int>0</int>
                </edit>
                <edit name="hinting">
                        <bool>true</bool>
                </edit>
                <edit name="autohint">
                        <bool>false</bool>
                </edit>
                <edit name="antialias" mode="assign">
                        <bool>true</bool>
                </edit>
                <test name="pixelsize" compare="less_eq">
                        <int>18</int>
                </test>
                <edit name="antialias" mode="assign" >
                        <bool>false</bool>
                </edit>
        </match>
        <match target="font" >
                <test name="family" compare="contains" >
                        <string>Microsoft Yahei</string>
                </test>
                <edit name="globaladvance">
                        <bool>false</bool>
                </edit>
                <edit name="spacing">
                        <int>0</int>
                </edit>
        </match>
</fontconfig>
如此,xft服务器就能找到合适的字体匹配。
4. 用户字体设置及编码
设置字体,我使用gtk,所以只设置了gtkrc文件,.gtkrc-2.0文件
代码:
style "user-font"
{
font_name = "Verdana, Microsoft YaHei 12"
}
widget_class "*" style "user-font"
gtk-theme-name="MacOS-X"
gtk-icon-theme-name="MacOS-X"
我使用startx系统进入X。所以要编辑.xinitrc文件,这是字体编码、还有输入法等。我的配置文件如下:
代码:
#!/bin/bash
#
# Setup locale
export GDK_USE_XFT=1
export C=zh_CN.utf8
export LC_CTYPE=zh_CN.utf8
#export LC_ALL=zh_CN.utf8

# Setup scim IM
LANG=zh_CN.utf8 scim -d
export XMODIFIERS="@im"="SCIM"
export GTK_IM_MODULE="scim"
export QT_IM_MODULE="scim"
exec fvwm 2>.fvwm.log

如果使用xdm登录,需要修改.Xclients

代码:

#!/bin/bash
#
# Setup locale
export GDK_USE_XFT=1

#
export LC_CTYPE=zh_CN.utf8

# if you want to zh_CN, open the 2 optionals
#export LC_ALL=zh_CN
#LC_ALL includes all of following 6 options
#export LC_TIME=zh_CN
#export LC_NUMERIC=zh_CN
export LC_NOMETAEY=zh_CN.utf8
export LC_MESSAGES=zh_CN.utf8
export LC_COLLATE=zh_CN.utf8
export C=zh_CN.utf8
#
# Setup fcitx IM
#export XMODIFIERS="@im=fcitx"
#export XIM=fcitx
#export XIM_PROGRAM=fcitx
#exec fcitx &
#
# Setup scim IM
LANG=zh_CN.utf8 scim -d
export XMODIFIERS="@im"="SCIM"
export GTK_IM_MODULE="scim"
export QT_IM_MODULE="scim"
#exec conky &
exec fvwm 2>.fvwm.log
#exec starte16

进入fvwm后,发现原来gb2312文件中中文都是乱码,所以需要进行编码转换,编码转换使用iconv程序,没有这个程序的需要emerge

代码:
emerge dev-haskell/iconv
对于需要文件名进行转换的文件需要使用:
代码:
emerge app-text/convmv
这是一个perl程序,可以转换从任意字符名字转换为utf-8。
由于iconv默认输入到终端,所以要需要文件重定向。-f (from) -t (to)
代码:
iconv -f gb2312 -t utf-8 gb2312-file > utf8file
格式转换后,需要修改fvwm字体,如果要 雅黑 字体则需要这样设置:
代码:
"xft:Microsoft YaHei:encoding=iso10646-1"

设置好后就可以显示中文了。
完毕。

效果图: