mkimgの次はcutterだ
cutter hoge.tex
すると、hedderというファイルと数式部分のファイルが多数ぶち撒かれる。要
注意だ。
#!/usr/bin/perl -w # file:cutter # TeX source cutter to get headder and equation part of tex $TimeStamp="Time-stamp: <05/09/09 03:10:03 fu7mu4>"; $Version="2.3macosx-vine"; # Special Thanks to ------- . ###Options## # $NoNumber="YES" : remove all equation number , ="NO" : don't remove $NoNumber="YES" ; # $Eqpart is output file name , ex. "$EqFile$i" :$i = 1,2,3... $EqFile="eqpart" ; # headder file name $HeadderFile = "headder" ; ###CODE### #initialize @mathenv = ( "equation" , "eqnarray" , "gather" , "align" , "alignat" , "multline" ); $FileNum = 0 ; #version and help print <<EOD; cutter Version $Version is wriiten at $TimeStamp cutter USAGE cutter file or cat \*\.tex | cutter No input , send me Ctrl-D EOD while (<>) { s/\%.*$// ; #remove all comments s/\\label\{.*\}// ; #remove all label commands s/\\tag(\*)?{.*\}// ; #remove all tags command if ( $_ =~ /\\document/ ) { $FileName = "$HeadderFile"; open(W,">${FileName}"); select W; } if ( $_ =~ /\\\[|\\begin\{(equation|eqnarray|gather|align|alignat|multline)\*?\}/ ) { $FileNum++ ; $FileName = "${EqFile}".$FileNum; open(W,">${FileName}"); select W; } if ( ${NoNumber} eq "YES" ) { foreach $env (@mathenv ) { s/\\begin\{$env\}/\\begin\{$env\*\}/g ; s/\\end\{$env\}/\\end\{$env\*\}/g ; } # for jlatex s/\\begin\{equation\*\}/\\\[/; s/\\end\{equation\*\}/\\\]/; } # s/^.*?(\\\[|\\begin\{equation\})/$1/; # s/(\\\]|\\end\{equation\}).*$/$1/; foreach $env (@mathenv ) { s/^.*?(\\\[|\\begin\{$env\*?\})/$1/; s/(\\\]|\\end\{$env\*?\}).*$/$1/; } print $_; if ( $_ =~ /\\begin\{document\}/) { close W; select STDOUT; } if ( $_ =~ /\\\]|\\end\{(equation|eqnarray|gather|align|alignat|multline)\*?\}/ ) { close W; select STDOUT; } } print <<EOD; see , there are $FileNum files EOD
eq2imgだ。
こいつの引数が大変すぎるから、mkimgが必要なんだ。実は~/.eq2imgというファ
イルを直読みするので~/.eq2imgに書き込み権限を許すと任意のコマンドが実行
可能なので注意しろよ。
#!/bin/bash # eq2img -- equation part of tex source to gif/png converter # using platex , dvips and ImageMagick -- TimeStamp="Time-stamp: <06/08/14 01:43:10 fu7mu4>" Version="1.0macosx-vine" ScriptName=$(basename "$0") INITFILE="${HOME}/.eq2img" ### CODE ### ShowUsage () { cat <<EOF $ScriptName Script for making transparent gif/png $ScriptName :USAGE $ScriptName {-h|-v} $ScriptName [-ne|-nq|-c color|-hf headderfile|-of outputfile|eqfile] -h :show help and quit -v :show version and quit -g / -p : convert to gif/png format -e / -np : with/without eps -q / -nq : need/remove equation file after this run -m / -nm : with/without message -w / -nw : with/without warning -i / -ni : input/don't input tex command directory -c color : change another foregrounf color -hf file : change headder file name -of file : change output file name EOF } ShowPara () { cat <<EOF $ScriptName Script is now configured values ... INITFILE $INITFILE DEFHEADDER $DEFHEADDER SOURCE $SOURCE OUTPUT $OUTPUT TMPDIR $TMPDIR Format $Format Color $Color NeedEPS $NeedEPS NeedEq $NeedEq EOF } ### read from init file ### if [ -r "$INITFILE" ] ; then . "$INITFILE" fi ### read from arguments of this script while [ "$1" != "" ] do if [ -r "$1" ] ; then #Input is readble readble="$1" else if [ "$1" == "-h" ] ; then ##help ShowUsage exit elif [ "$1" == "-v" ] ; then echo "$ScriptName Version $Version" echo "Last Modified $TimeStamp" ##help exit elif [ "$1" == "-batch" ] ; then TeXmode="batch" elif [ "$1" == "-nonstop" ] ; then TeXmode="nonstop" elif [ "$1" == "-p" ] ; then Format="png" elif [ "$1" == "-g" ] ; then Format="gif" elif [ "$1" == "-nw" ] ; then NeedWarning="NO" elif [ "$1" == "-w" ] ; then NeedWarning="YES" elif [ "$1" == "-nm" ] ; then NeedMessage="NO" elif [ "$1" == "-m" ] ; then NeedMessage="YES" elif [ "$1" == "-ne" ] ; then NeedEPS="NO" elif [ "$1" == "-e" ] ; then NeedEPS="YES" elif [ "$1" == "-nq" ] ; then NeedEq="NO" elif [ "$1" == "-q" ] ; then NeedEq="YES" elif [ "$1" == "-i" ] ; then NeedInput="YES" elif [ "$1" == "-ni" ] ; then NeedInput="NO" elif [ "$1" == "-hf" ] ; then if [ "$2" != "" ] ; then DEFHEADDER=$2 shift else ShowUsage fi elif [ "$1" == "-of" ] ; then if [ "$2" != "" ] ; then OUTPUT=$2 shift else ShowUsage fi elif [ "$1" == "-c" ] ; then if [ "$2" != "" ] ; then Color=$2 shift else ShowUsage fi else SOURCE=${readble:-$1} ##SOURCE is new file fi fi shift done ### default variables DEFHEADDER=${DEFHEADDER:-"headder"} HEADDER=${TEXHEADDERFILE:-$DEFHEADDER} SOURCE=${readble:-"eq2gif$$"} OUTPUT=${OUTPUT:-$SOURCE} NeedMessage=${NeedMessage:-"YES"} NeedWarning=${NeedWarning:-"YES"} NeedEPS=${NeedEPS:-"YES"} NeedEq=${NeedEq:-"YES"} NeedInput=${NeedInput:-"NO"} TeXmode=${TeXmode:-"batch"} Color=${Color:-"yellow"} TMPDIR=${DEFTMPDIR:-"/tmp/eq2img$$"} Format=${Format:-"gif"} ### variables SECTION END ### ## SHOW PID ## #in order to kill this process when platex waiting for your input if [ $NeedMessage == "YES" ] ; then echo "$ScriptName 's PID : $$" else if [ $TeXmode != "batch" ]; then if [ $TeXmode != "nonstop" ] ; then echo "$ScriptName 's PID :$$" fi fi fi ## Make TMPDIR ## if [ ! -d "$TMPDIR" ] ; then mkdir "$TMPDIR" fi if [ ! -d "$TMPDIR" ] ; then if [ $NeedWarning == "YES" ]; then echo "Cannot Make $TMPDIR , exit" echo "check DEFTMPDIR variable" fi exit 1 fi ## Define file names ## TMPBASE="${TMPDIR}/${SOURCE}" TMPTEX="${TMPBASE}.tex" TMPAUX="${TMPBASE}.aux" TMPLOG="${TMPBASE}.log" TMPDVI="${TMPBASE}.dvi" TMPEPS="${TMPBASE}.eps" TMPGIF="${TMPBASE}.${Format}" ### making tex file section ### ## make headder ## if [ -r "$HEADDER" ]; then cat "$HEADDER" > "$TMPTEX" #headder exist else echo '\documentclass[12pt]{article}' > "$TMPTEX" #use default headder echo '\usepackage{amsmath,amssymb}' >> "$TMPTEX" echo '\begin{document}' >> "$TMPTEX" fi echo '\pagestyle{empty}' >> "$TMPTEX" #pagestyle empty is needed for dvips ## merge headder with source of tex ## if [ -r "$SOURCE" ]; then cat "$SOURCE" >> "$TMPTEX" else if [ $NeedInput == "YES" ] ; then echo "type tex command , that treat as in \[...\] env" read -er TEXLINEINPUT ## directory tex source input echo '\[' >> "$SOURCE" echo $TEXLINEINPUT >> "$SOURCE" echo '\]' >> "$SOURCE" cat "$SOURCE" >> "$TMPTEX" else if [ $NeedWarning == "YES" ] ; then echo "can not read $SOURCE and not recieve directly input" fi /bin/rm -rf "$TMPDIR" exit fi fi echo '\end{document}' >> "$TMPTEX" ## remove equation part file if [ "$NeedEq" != "YES" ] ; then if [ -e "$SOURCE" ] ; then /bin/rm -f "$SOURCE" fi fi ### making tex file section ### cd "$TMPDIR" ### compile and convert ### ## platex compile TEX->DVI## if [ "$TeXmode" == "batch" ] ; then platex -interaction=batchmode "$TMPTEX" > /dev/null 2> /dev/null elif [ "$TeXmode" == "nonstop" ] ; then platex -interaction=nonstopmode "$TMPTEX" > /dev/null 2> /dev/null else platex "$TMPTEX" > /dev/null 2> /dev/null fi if [ ! -r "$TMPDVI" ] ; then if [ $NeedWarning == "YES" ] ; then echo "DVI file $TMPDVI is not exist" fi exit 1 fi ## by dvips ,DVI -> EPS dvips -q -E "$TMPDVI" -o "$TMPEPS" if [ ! -r "$TMPEPS" ] ; then if [ $NeedWarning == "YES" ] ; then echo "Enhanced PostScript file $TMPEPS is not exist" fi exit 1 fi ## EPS -> GIF , by convert (ImageMagick) convert -density 800x800 "$TMPEPS" -transparent white -fill "$Color" -fuzz 15% -opaque black "$TMPGIF" ##convert # first file name is input (format is automatic detected) # second file name is output (format is automatic detected) # -density XxY :resolove along with x and y direction (X,Y dpi) # -transparent color : transparent an area where is painted in that # -color fill color area : fill color in an area where is given bellow # "-opaque" option # -fuzz parcent : error for color # -opaque color : return an area where patinted given color cd "$OLDPWD" ### END SECTION ### ## move need files if [ $NeedEPS == "YES" ] ; then cp "$TMPEPS" "${OUTPUT}.eps" fi cp "$TMPGIF" "${OUTPUT}.${Format}" ## remove the others /bin/rm -rf "$TMPDIR"
設定ファイル.eq2img
例えばこんな設定でどうだ。
#!/bin/sh # # eq2gif configure file # # Time-stamp: <05/09/13 15:45:32 fu7mu4> # this read by eq2gif (3.0-) using source command if this exist in $HOME. # this file gives eq2gif default values # you can add some commands for initializing echo "now reading init file" ###platex mode### # platex work with under batch / nonstop / default mode TeXmode="batch" # it supports "batch" , "nonstop" or "errorstop"=other # NOTICE : some platex system doesn't support "nonstop" ###headder file name### # headder file name is (1) env variable TEXHEADDERFILE value or # (2) variable DEFHEADDER value . DEFHEADDER="headder" # if headder file not exist , eq2gif use default value . ### Temporary Directory name### # TMP dir name , $$ represent process id DEFTMPDIR="/tmp/Eq2Gif$$" # if TMPDIR not exist , eq2gif try to make it , and fail to make , # eq2gif stop ### Do you want temporary files ?## # equation part file NeedEq="YES" #NO # Enhanced PostScript file NeedEPS="YES" #NO ### Do you want some message ?## # Message is PID or some info , if TeXmode=batch or nonstop . YES # means you want to recieve PID info NeedMessage="YES" #"NO" # Warning is Warning and Error Messages. YES means you want to recieve # Warning and Error messages. NeedWarning="YES" #YES or NO ### Color ### # Background Color: tranparent . Foreground Color: white, black, red, # green, blue, yellow, pink...are supported #Color="white" Color="black" # Convert can read many color name directory. # if you don't know color name, use RGB or CMYK representation # for example red color # "rgb(255,0,0)" r=255,g=b=0, each integer range 0 to 255 # "rgb(100%,0%,0%)" r=100%,g=b=0% each float range is 0% to 100% # "#f00" r=0xf g=b=0x0 # "#ff0000" for rrggbb , or "#ffff00000000" for rrrrggggbbbb # CMYK representation is the same as rgb # cmyk(100%,100%,100%,100%) or cmyk(255,255,255,255) # except hex, # if you want to know about coloro name, see http://www.imagemagick.org/script/color.php