Dockerized web application to conveniently convert SVG to LaTeX files.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

77 lines
2.5 KiB

#!/bin/sh
#################################################################
# Convert a vector graphic to a .tex file and use it with
# Copyright (C) 2020 Maximilian Stiefel (stiefel.maximilian@online.de)
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 2.
#
# 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, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# Created: 29. June 2018
# CLI usage: ./svg_to_latex.sh path_to_graphic.svg
# Required PKGs: inkscape (tested w/ version 1.0), rpl
#
#################################################################
#################################################################
# Vars
#################################################################
NU_PARAMS=1
PDF_EXT=pdf
TEX_EXT=pdf_tex
#################################################################
# Action
#################################################################
# Check if the expected number of parameters is given.
if [ $# < $NU_PARAMS ]
then
echo "$0: Error: Illegal number of parameters."
exit 1;
fi
GRAPHIC_FILE=$1
BASE=$(basename -- "$GRAPHIC_FILE")
EXTENSION=${GRAPHIC_FILE##*.}
PDF_FILE=${GRAPHIC_FILE%.$EXTENSION}.$PDF_EXT
TEX_FILE=${GRAPHIC_FILE%.$EXTENSION}.$TEX_EXT
if [ $# -eq $(($NU_PARAMS+1)) ]
then
NEW_PDF_FILE="./"$2"/"${BASE%.$EXTENSION}.$PDF_EXT
NEW_TEX_FILE="./"$2"/"${BASE%.$EXTENSION}.$TEX_EXT
else
NEW_PDF_FILE=$PDF_FILE
NEW_TEX_FILE=$TEX_FILE
fi
# Convert to LaTeX
inkscape -D --export-latex --export-filename=$PDF_FILE $GRAPHIC_FILE
if [ $? -eq 1 ]
then
exit 1
fi
# Perform one small mod to be able to use use file directly with \input{}
rpl -q ${PDF_FILE##*/} $NEW_PDF_FILE $TEX_FILE
if [ $? -eq 1 ]
then
exit 1
fi
echo "$0: Produced $NEW_PDF_FILE and $NEW_TEX_FILE. Use "
echo ""
printf "%s\n" "\\begin{figure}[H]"
printf "%s\n" " \centering"
printf "%s\n" " \def\svgwidth{\columnwidth}"
printf "%s\n" " \input{$TEX_FILE}"
printf "%s\n" " \caption{}"
printf "%s\n" " \label{fig:${BASE%.*}}"
printf "%s\n" "\end{figure}"
echo ""
echo "to include the graphic into your document."
exit 0