#!/bin/bash # # Syntax: figstr2psfrag [-h] [-l] [-x] [-s scale] fig_file [...] # # Purpose: Extracts text strings from a fig file and returns the corresponding # psfrag commands (\psfrag{string}{string}). # The -l flag indicates that the default string position matching # of psfrag should be used (i.e. left base line positioning [Bl]) # instead of [] (i.e. center positioning). # The -x flag means that the horizontal alignment positioning should # be taken from xfig (i.e., the Justification field). The vertical # alignment positioning is then omitted (i.e., set to the default # value c). # The -s flag allows to specify a scaling. # The -h flag shows the help info for this command. # Created: Dec 14, 2005 by Bart De Schutter # Last revised: Jul 31, 2011 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: xfig, latex scale="" center_str="[]" xfig_alignment=0 while getopts :hlxs: option do case "$option" in l) center_str="";; x) xfig_alignment=1;; s) scale=$OPTARG;; :) echo >&2 echo >&2 "Option -$OPTARG requires an argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 echo >&2 exit 1;; h) sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; \?) echo >&2 echo >&2 "Unknown option: $OPTARG" echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; esac done shift $(($OPTIND-1)) if [ $# -eq 0 ]; then echo >&2 echo >&2 "ERROR: ${0##*/} requires at least 1 input argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi if [ -n "$scale" -a -z "$center_str" ] then center_str="[Bl]" # I.e. the default string position matching of psfrag. fi IFS='' # keep spaces as spaces in read command below for fil in "$@" do set -f # turn filename expansion off fil=${fil%.fig}.fig if [ -f "$fil" ] then echo "psfrag translations for $fil" echo "------------------------------------------------------------------" grep "^4 " "$fil" | cut -f 14- -d ' ' | sed 's/\\001$//' | sort -u | while read LINE; do if [ $xfig_alignment -eq 1 ] then alignment=$(grep -e "$LINE" "$fil" | grep -m 1 "^4 " | cut -f 2 -d ' ') case "$alignment" in 0 ) center_str="[l]";; 1 ) center_str="[c]";; 2 ) center_str="[r]";; * ) echo >&2 echo >&2 "ERROR: Unknown alignment $alignment in fig file $fil for" echo >&2 " string $LINE" echo >&2 " Resave fig file or run ${0##*/} without the -x option." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 esac fi psfrag_arg="$(echo $LINE | sed 's/\\/\\\\/g')" if [ -z "$scale" ] then echo "\\psfrag{$psfrag_arg}${center_str}${center_str}{$LINE}" else echo "\\psfrag{$psfrag_arg}${center_str}${center_str}[$scale]{$LINE}" fi done echo fi done