>From 967beab61d94f966c06f245b9c22e1e702d6c785 Mon Sep 17 00:00:00 2001 From: Akira Yokosawa <akiyks@xxxxxxxxx> Date: Sun, 20 Oct 2019 00:51:00 +0900 Subject: [PATCH v3 2/6] Add synctex-forward.sh This script sets up "% mainfile:" tags in sub .tex files with a suitable "perfbook-xx.tex" file name. They enable SyncTeX forward search to perfbook-xx.pdf. Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx> --- utilities/synctex-forward.sh | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 utilities/synctex-forward.sh diff --git a/utilities/synctex-forward.sh b/utilities/synctex-forward.sh new file mode 100755 index 00000000..312f9cc3 --- /dev/null +++ b/utilities/synctex-forward.sh @@ -0,0 +1,89 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Set "% mainfile:" lines with proper "% mainfile: <...>" tags in +# sub .tex files. +# +# With no argument, the main file will be "perfbook.tex", +# which will do nothing by default. +# With abbrev target such as "1c", "hb", and so on, the main file +# will be "perfbook-1c.tex", perfbook-hb.tex", and so on. +# +# Depth of subdirectory is deduced from the path of each sub .tex file. +# +# Changes made by this script can be reverted by running without +# argument. +# +# WARNING: By runnig this script, your working tree will be modified. +# It is highly recommented to commit your changes before running +# this script. + +# If LATEX_OPT does not have "synctex", do nothing +if ! echo $LATEX_OPT | grep -q synctex ; then + echo "LATEX_OPT has no synctex option. Exiting..." + exit 1 +fi + +# warn if git status is not clean later +gitstatus=`git status --porcelain | wc -l` +if [ $gitstatus != "0" ] ; then + wasnotclean=1 +else + wasnotclean=0 +fi + +if [ $# -eq 0 ] ; then + main="perfbook.tex" + change="reverted" +else + case $1 in + 2c) + main="perfbook.tex" + change="reverted" + ;; + 1c|hb|tcb|msnt|mstx|msr|msn|1csf|msns|mss) + main="perfbook-$1.tex" + change="modified" + ;; + *) + echo "Unknown target!!" + exit 1 + ;; + esac +fi + +tmpf=`mktemp` +texfiles=`find . -name '*.tex' -print` +modified=0 +for i in $texfiles +do + c=$(expr `echo $i | grep -o "/" | wc -l` - 1) + x= + for j in $(seq 1 $c) + do + x=..\\/$x + done + mainpath=$x$main + pattern="s/% mainfile: .*perfbook.*\.tex/% mainfile: $mainpath/" + cat $i | sed -e "$pattern" > $tmpf + if ! diff -q $i $tmpf >/dev/null ; then + echo "$i $change." + cp -f $tmpf $i + modified=1 + fi +done + +if [ $modified -eq 0 ] ; then + echo "No modification." +else + if [ $main != "perfbook.tex" -a $wasnotclean -eq 1 ] ; then + echo "### Git status was not clean." + echo "### To revert the changes, just run '$0'." + fi +fi + +# check if synctex database exists +mainbase="${main%.tex}" +if [ `ls -1 perfbook* | grep -c $mainbase.synctex` -eq 0 ] ; then + echo "### $mainbase.synctex*: file not found." +fi -- 2.17.1