File: ytxt2tex

package info (click to toggle)
yacas 1.3.6-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 7,176 kB
  • ctags: 3,520
  • sloc: cpp: 13,960; java: 12,602; sh: 11,401; makefile: 552; perl: 517; ansic: 381
file content (48 lines) | stat: -rwxr-xr-x 1,645 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh

# Convert plaintext Yacas-format documentation to TeX files
# Usage: ytxt2tex [-o outputfile] file1.txt [file2.txt] ...
# source files must have extension ".txt"
# output file is "file1.tex" if the -o option is not given
# note: if many txt files are given, the first one must *INCLUDE all others without txt extension
# Requirements: sh, perl, yacas
# (the "yacas" executable must be available on the path and the library with manmake scripts installed, e.g. /usr/local/share/yacas/manmake/*)

runyacas="yacas" # executable name and command-line options if any
yacasdir="`$runyacas -d`" # yacas installation directory
tmpdir="/tmp" # for temporary files

output=""
if [ x"$1" = x-o ]; then
    shift
    output="$1"
    shift
fi

if [ x"$1" = x ]; then
	echo "`basename $0`: convert Yacas-style plaintext docs to TeX"
	echo "Usage: `basename $0` [-o outputfile.tex] file1.txt [file2.txt] ..."
else
    # Store the name of the main txt file, convert all files to Yacas first, using tmpdir
    if [ -r "$1" ]; then
	mainfile="$1"
	[ x"$output" = x ] && output=`dirname $1`/`basename $1 .txt`.tex
	echo "Will create TeX file '$output'"
    else
	echo "Error: cannot read file '$1', aborting."
	exit
    fi
    while [ "x$1" != x ]; do
	if [ -r "$1" ]; then
	    newname=`basename "$1" .txt`
	    perl "$yacasdir"/manmake/txt2yacasdoc.pl < "$1" > "$tmpdir"/"$newname"
	else
	    echo "Error: cannot read file '$1', skipping."
	fi
	shift
    done
    # run book2TeX.sh on the main file
    ( cd "$tmpdir"; "$yacasdir/manmake/book2TeX.sh" -run yacas `basename "$mainfile" .txt` `basename "$output"`)
    mv "$tmpdir/$output" "$output"

fi