erste öffentliche Version

This commit is contained in:
Beat Jäckle 2023-05-23 09:05:43 +02:00
parent 913fdf8899
commit a104b165ed
2 changed files with 103 additions and 2 deletions

View file

@ -1,4 +1,21 @@
# latex2utf8
# latex2utf8
Konvertiert .tex Dateien vom mit 'applemac' kodierung zu utf8.
Das Programm ist auf Bash geschrieben. Bitte benütze GNU+Linux dazu.
## Ausführen
Das Programm kann unter GNU+Linux mit `bash latex2utf8.sh FILE.tex` ausgeführt werden. Die Originaldatei wird als FILE.tex.raw umbenannt. FILE.tex ist anschliessend in UTF8 geschrieben.
Es wird empfohlen die LaTeX Datei mit Git zu versionieren.
## Installation
```
ln -s `realpath latex2utf8.sh` ~/.local/bin/latex2utf8
```
### mögliche Probleme
`~/.local/bin` sollte in PATH vorkommen, damit latex2utf8 gefunden wird.

84
latex2utf8.sh Executable file
View file

@ -0,0 +1,84 @@
#!/bin/bash
#
# latex2utf8.sh
#
# Copyright 2023 Beat Jäckle <beat@git.jdmweb2.ch>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
if [ -z $1 ]
then
echo $0 FILE.tex ; exit 1
else
file="$1"
fi
if [ $(grep -c 'usepackage[utf8]{inputenc}' "$file") -gt 0 ]
then
echo It seems this file "$file" is already updated.
read -p "Should convet anyway? [y/N] " a
if ! [ {$a}x == "yx" ];then exit 1;fi
fi
if [ "${file:(-8)}" == '.tex.raw' ]
then
cp "${file}" "${file::(-4)}"
file="${file::(-4)}"
fi
set -ue
if [ ! -f "${file}.raw" ]
then
cp "$file" "${file}.raw"
fi
fileType=$(file -bi "${file}")
if [ "$fileType" != "text/x-tex; charset=utf-8" ];
then
#~ sed -i 's|ǎ| |g' "$file"
#U+008A = ä
#~ sed -i 's|Š|ä|g' "$file"
#U+009A=ö
#~ sed -i 's|š|ö|g' "$file"
LANG=de_CH iconv -t utf-8 "${file}.raw" -o "$file"
fi
sed -i 's|\\usepackage[applemac]{inputenc}|\\usepackage[utf8]{inputenc}|g' "$file"
sed -i 's|\\"a|ä|g' "$file"
sed -i 's|\\"o|ö|g' "$file"
sed -i 's|\\"u|ü|g' "$file"
sed -i 's|\\"A|Ä|g' "$file"
sed -i 's|\\"O|Ö|g' "$file"
sed -i 's|\\"U|Ü|g' "$file"
sed -i "s|Ê| |g" "$file"
sed -i "s|Õ|'|g" "$file"
sed -i "s|<7C>|'|g" "$file"
sed -i $'s|\u009f|ü|g' "$file" # 9f->ü
sed -i $'s|\u009a|ö|g' "$file"
sed -i $'s|\u008a|ä|g' "$file"
sed -i $'s|\u0086|Ü|g' "$file"
sed -i $'s|\u0080|Ä|g' "$file"
sed -i $'s|\u0085|Ö|g' "$file"
sed -i 's|š|ö|g' "$file"
sed -i 's|Š|ä|g' "$file"
# Diese Zeilen können angepasst werden,
# um gleich ein paar verbesserungen an den Dokumenten vorzunehmen
sed -i 's|\.eps\}|\.pdf\}|g' "$file"
sed -i 's|\\input{/Users/.../MyStyle.tex}|\\usepackage{MyStyle}|g' "$file"
sed -i 's|\\Bild{|\\Bild{img/|g' "$file"
sed -i 's|\\Bildlinks{|\\Bildlinks{img/|g' "$file"
sed -i 's|\\Bildrechts{|\\Bildrechts{img/|g' "$file"
sed -i 's|{img/img/|{img/|g' "$file"