Skip to contentSkip to conversation

Trial of replacing hyphens with en-dashes

RFC PATCH In review Akira Yokosawa 2 participants 5 messages Aug 13, 2016 – Aug 14, 2016

lore
Share & tools
lore
#0 lore raw

cover Trial of replacing hyphens with en-dashes

From a63dd50b648013af5780341f9c740bf9d9f6b65d Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Sat, 13 Aug 2016 11:17:19 +0900
Subject: [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes

Hi Paul,

This is an RFC patch series of my attempt to replace hyphens used for ranges of numbers with en-dashes.
Instead of sending modifications in LaTeX sources as patches, I'm submitting scripts which do the replacements on the fly.
The "sed" script is fairly stable now, and there is no false positives AFAIK.
There might still be false negatives I'm not aware of. Any false positive would be addressed by adding a sed pattern.
As a bonus, the sed pattern also contains fixes of typos such as "line~mm-nn".

To try the replacement, at the top directory of perfbook, invoke the script by "sh utilities/dohyphen2endash.sh".
You need to be in a clean git repository. This check is to ensure that you can revert the changes made by the script by "git reset --hard". So you might want to try this series on a test branch.
Or the check of git status can be overridden by a "-f" or "--force" option.

The modification by the scripts can be reviewed by "git diff" afterwards.

It is up to the editor's choice whether or not to commit the result.

Just adding the scripts to the repository is fine with me.

Thanks, Akira
------

Akira Yokosawa (3):
Trial of replacing hyphens with en-dashes for number ranges dohyphen2endash.sh: Add check of git status dohyphen2endash.sh: Use mktemp to create temp file

 utilities/dohyphen2endash.sh | 74 ++++++++++++++++++++++++++++++++++++++++++++
 utilities/hyphen2endash.sh   | 50 ++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+)
 create mode 100644 utilities/dohyphen2endash.sh
 create mode 100644 utilities/hyphen2endash.sh
Signature · 1 line
1.9.1
#1 lore raw

RFC PATCH 1/3 Trial of replacing hyphens with en-dashes for number

From 449dc8ab744b917a66ea1a38b7f5d7af09ba8025 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Wed, 10 Aug 2016 06:59:07 +0900
Subject: [RFC PATCH 1/3] Trial of replacing hyphens with en-dashes for number
ranges

This commit adds scripts to do replacing.
By doing "sh utilities/dohyphen2endash.sh" in the top directory, hyphens used in number ranges such as "Lines~m-n" will be replaced with en-dashes such as "Lines~m--n" in LaTeX sources. For patterns used to find replacement candidates, see "utilities/hyphen2endash.sh".

---
 utilities/dohyphen2endash.sh | 36 +++++++++++++++++++++++++++++++
 utilities/hyphen2endash.sh   | 50 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)
 create mode 100644 utilities/dohyphen2endash.sh
 create mode 100644 utilities/hyphen2endash.sh
utilities/dohyphen2endash.sh new file +36 -0
new file mode 100644
index 0000000..3270983
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# Apply hypen2endash.sh for all .tex files
+#
+# 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; either version 2 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, you can access it online at
+# http://www.gnu.org/licenses/gpl-2.0.html.
+#
+# Copyright (C) Akira Yokosawa, 2016
+#
+# Authors: Akira Yokosawa <[email protected]>
+
+texfiles=`find . -name '*.tex' -print`
+for i in $texfiles
+do
+	basename="${i%.tex}"
+#	echo $basename
+	sh ./utilities/hyphen2endash.sh $basename.tex > $basename.tmp
+	if diff -q $basename.tex $basename.tmp >/dev/null
+	then
+		rm $basename.tmp
+	else
+		echo "$basename.tex modified"
+		mv -f $basename.tmp $basename.tex
+	fi
+done
utilities/hyphen2endash.sh new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

RFC PATCH 2/3 dohyphen2endash.sh: Add check of git status

In reply to Akira Yokosawa

From 1fc4b3e11e22f12c0ca347cbbcae6dae329cdcf0 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Fri, 12 Aug 2016 23:58:46 +0900
Subject: [RFC PATCH 2/3] dohyphen2endash.sh: Add check of git status

This commit also adds option "-f" and "--force" to override the check.

---
 utilities/dohyphen2endash.sh | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
utilities/dohyphen2endash.sh +38 -0
index 3270983..05557f0 100644
@@ -1,6 +1,9 @@
 #!/bin/sh
 #
 # Apply hypen2endash.sh for all .tex files
+# If invoked in non-clean git status, this script will abort.
+# If invoked with the "--force" option, this script will continue
+# regardless of git status.
 #
 # 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
@@ -20,6 +23,41 @@
 #
 # Authors: Akira Yokosawa <[email protected]>
 
+# parse option
+TEMP=`getopt -o f --long force -- "$@"`
+
+if [ $? != 0 ] ; then echo "Error in parse option..." >&2 ; exit 1 ; fi
+
+eval set -- "$TEMP"
+
+forced=0
+
+while true ; do
+	case "$1" in
+		-f|--force) forced=1 ; shift ;;
+		--) shift ; break ;;
+		*) echo "Unknown option!" ; exit 1 ;;
+	esac
+done
+# check if we are in git repository
+if ! test -e .git
+then
+	echo "not in a git repository"
+	exit 1
+fi
+# check if companion script exists
+if ! test -e utilities/hyphen2endash.sh
+then
+	echo "utilities/hyphen2endash.sh not found."
+	exit 1
+fi
+# check if git status is clean
+gitstatus=`git status --porcelain | wc -l`
+if [ $forced -eq 0 -a $gitstatus != "0" ]
+then
+	echo "git status not clean --- aborting."
+	exit 1
+fi
 texfiles=`find . -name '*.tex' -print`
 for i in $texfiles
 do
Signature · 1 line
1.9.1
#3 lore raw

RFC PATCH 3/3 dohyphen2endash.sh: Use mktemp to create temp file

In reply to Akira Yokosawa

From a63dd50b648013af5780341f9c740bf9d9f6b65d Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Sat, 13 Aug 2016 11:02:39 +0900
Subject: [RFC PATCH 3/3] dohyphen2endash.sh: Use mktemp to create temp file

---
 utilities/dohyphen2endash.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
utilities/dohyphen2endash.sh +5 -5
index 05557f0..2a0fdc7 100644
@@ -59,16 +59,16 @@ then
 	exit 1
 fi
 texfiles=`find . -name '*.tex' -print`
+tmpf=`mktemp`
 for i in $texfiles
 do
 	basename="${i%.tex}"
 #	echo $basename
-	sh ./utilities/hyphen2endash.sh $basename.tex > $basename.tmp
-	if diff -q $basename.tex $basename.tmp >/dev/null
+	sh ./utilities/hyphen2endash.sh $basename.tex > $tmpf
+	if ! diff -q $basename.tex $tmpf >/dev/null
 	then
-		rm $basename.tmp
-	else
 		echo "$basename.tex modified"
-		mv -f $basename.tmp $basename.tex
+		cp -f $tmpf $basename.tex
 	fi
 done
+rm -f $tmpf
Signature · 1 line
1.9.1
#4 lore raw
In reply to Akira Yokosawa
Quoted 24 lines · Akira Yokosawa
Quoted 1 line

From a63dd50b648013af5780341f9c740bf9d9f6b65d Mon Sep 17 00:00:00 2001

From: Akira Yokosawa <[email protected]>
Date: Sat, 13 Aug 2016 11:17:19 +0900
Subject: [RFC PATCH 0/3] Trial of replacing hyphens with en-dashes

Hi Paul,

This is an RFC patch series of my attempt to replace hyphens used for ranges of numbers with en-dashes.
Instead of sending modifications in LaTeX sources as patches, I'm submitting scripts which do the replacements on the fly.
The "sed" script is fairly stable now, and there is no false positives AFAIK.
There might still be false negatives I'm not aware of. Any false positive would be addressed by adding a sed pattern.
As a bonus, the sed pattern also contains fixes of typos such as "line~mm-nn".

To try the replacement, at the top directory of perfbook, invoke the script by "sh utilities/dohyphen2endash.sh".
You need to be in a clean git repository. This check is to ensure that you can revert the changes made by the script by "git reset --hard". So you might want to try this series on a test branch.
Or the check of git status can be overridden by a "-f" or "--force" option.

Quoted 5 lines

The modification by the scripts can be reviewed by "git diff" afterwards.

It is up to the editor's choice whether or not to commit the result.

Just adding the scripts to the repository is fine with me.

And, after inspecting the scripts, I took this approach.

Thank you!

Thanx, Paul

Quoted 17 lines

Thanks, Akira
------

Akira Yokosawa (3):
Trial of replacing hyphens with en-dashes for number ranges dohyphen2endash.sh: Add check of git status dohyphen2endash.sh: Use mktemp to create temp file

 utilities/dohyphen2endash.sh | 74 ++++++++++++++++++++++++++++++++++++++++++++
 utilities/hyphen2endash.sh   | 50 ++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+)
 create mode 100644 utilities/dohyphen2endash.sh
 create mode 100644 utilities/hyphen2endash.sh
Signature · 1 line
1.9.1