From a104b165ed2a823d2bcda1b19f8eb23c9af02a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20J=C3=A4ckle?= Date: Tue, 23 May 2023 09:05:43 +0200 Subject: [PATCH] =?UTF-8?q?erste=20=C3=B6ffentliche=20Version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 21 +++++++++++-- latex2utf8.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) create mode 100755 latex2utf8.sh diff --git a/README.md b/README.md index bdc8dcb..8a6d83d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/latex2utf8.sh b/latex2utf8.sh new file mode 100755 index 0000000..b53f3d7 --- /dev/null +++ b/latex2utf8.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# latex2utf8.sh +# +# Copyright 2023 Beat Jäckle +# +# 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 . + +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|�|'|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"