#!/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"