Skip to contentSkip to conversation

Makefile: Add check of \crefrange or \clnrefrange misuse

PATCH Superseded Akira Yokosawa 2 participants 3 messages Feb 14, 2020 – Feb 15, 2020 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: Add check of \crefrange or \clnrefrange misuse

From c0b6af552c7d5ade1b721ba4d6bd3c42e0f913e1 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Fri, 14 Feb 2020 22:42:04 +0900
Subject: [PATCH] Makefile: Add check of \crefrange and \clnrefrange misuse

To prevent typos simillar to the one fixed in commit b3b06a98bb7c ("datastruct.tex: fix some minor typos") to happen again, add checks to detect the following patterns of misuses:

... \cref{label A}{label B} ...

... \cref{long label X}
{another long label Y}

In the formar case, counts of violating lines are presented in the error message.
In the latter case, only the file name can be presented due to the "-zo" option to enable multi-line pattern search.

Note: There can be false negatives in the check.
For example, it can't not detect:

... \cref{label E}% some comment
{label F}

, at the moment.

---
 Makefile | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
Makefile +29 -0
index ccc840be..cb9ef668 100644
@@ -131,6 +131,11 @@ LINEREF_ENV_END     := $(shell grep -l -F '\end{lineref}'     $(LATEXSOURCES))
 LINELABEL_ENV := $(sort $(LINELABEL_ENV_BEGIN) $(LINELABEL_ENV_END))
 LINEREF_ENV   := $(sort $(LINEREF_ENV_BEGIN) $(LINEREF_ENV_END))
 
+CREFPTN    := '\\[Cc]ref{[^{]+}\s*{[^}]+}'
+CLNREFPTN  := '\\[Cc]lnref{[^{]+}\s*{[^}]+}'
+CREFPAIR   := $(shell grep -l -zo -E $(CREFPTN)   $(LATEXSOURCES))
+CLNREFPAIR := $(shell grep -l -zo -E $(CLNREFPTN) $(LATEXSOURCES))
+
 SOURCES_OF_SNIPPET_ALL := $(shell grep -r -l -F '\begin{snippet}' CodeSamples)
 SOURCES_OF_LITMUS      := $(shell grep -r -l -F '\begin[snippet]' CodeSamples)
 SOURCES_OF_LTMS        := $(patsubst %.litmus,%.ltms,$(SOURCES_OF_LITMUS))
@@ -202,6 +207,30 @@ endif
 		echo "Substitute 'fcvref' for 'lineref' in $(LINEREF_ENV)." ; \
 		exit 1 ; \
 	fi
+	@if [ ! -z "$(CREFPAIR)" -a "$(CREFPAIR)" != " " ]; then \
+		echo "------" ; \
+		if grep -q -E $(CREFPTN) $(CREFPAIR) ; then \
+			grep -n -B 2 -A 2 -E $(CREFPTN) $(CREFPAIR) ; \
+		else \
+			grep -zo -B 2 -A 2 -E $(CREFPTN) $(CREFPAIR) ; \
+			echo ; \
+		fi ; \
+		echo "------" ; \
+		echo "Need to use \[Cc]refrange in $(CREFPAIR)." ; \
+		exit 1 ; \
+	fi
+	@if [ ! -z "$(CLNREFPAIR)" -a "$(CLNREFPAIR)" != " " ]; then \
+		echo "------" ; \
+		if grep -q -E $(CLNREFPTN) $(CLNREFPAIR) ; then \
+			grep -n -B 2 -A 2 -E $(CLNREFPTN) $(CLNREFPAIR) ; \
+		else \
+			grep -zo -B 2 -A 2 -E $(CLNREFPTN) $(CLNREFPAIR) ; \
+			echo ; \
+		fi ; \
+		echo "------" ; \
+		echo "Need to use \[Cc]lnrefrange in $(CLNREFPAIR)." ; \
+		exit 1 ; \
+	fi
 	echo > qqz.tex
 	echo > contrib.tex
 	echo > origpub.tex
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/1 Makefile: Add check of \crefrange and \clnrefrange misuse

From f445ac887a125bbff303b80921f981ea0704c748 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Sat, 15 Feb 2020 08:36:53 +0900
Subject: [PATCH v2] Makefile: Add check of \crefrange and \clnrefrange misuse

To prevent typos simillar to the one fixed in commit b3b06a98bb7c ("datastruct.tex: fix some minor typos") to happen again, add checks to detect the following patterns of misuses:

... \cref{label A}{label B} ...

... \cref{long label X}
{another long label Y}

In the formar case, counts of violating lines are presented in the error message.
In the latter case, only the file name can be presented due to the "-zo" option to enable multi-line pattern search.

Note: There can be false negatives in the check.
For example, it can't not detect:

... \cref{label E}% some comment
{label F}

, at the moment.

---
Hi Paul,

This one uses a regex to cover both \cref and \clnref pattern.

Thanks, Akira
--

 Makefile | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
Makefile +15 -0
index ccc840be..7d1ec630 100644
@@ -131,6 +131,9 @@ LINEREF_ENV_END     := $(shell grep -l -F '\end{lineref}'     $(LATEXSOURCES))
 LINELABEL_ENV := $(sort $(LINELABEL_ENV_BEGIN) $(LINELABEL_ENV_END))
 LINEREF_ENV   := $(sort $(LINEREF_ENV_BEGIN) $(LINEREF_ENV_END))
 
+CREFPTN    := '\\[Cc](ln)?ref{[^{]+}\s*{[^}]+}'
+CREFPAIR   := $(shell grep -l -zo -E $(CREFPTN)   $(LATEXSOURCES))
+
 SOURCES_OF_SNIPPET_ALL := $(shell grep -r -l -F '\begin{snippet}' CodeSamples)
 SOURCES_OF_LITMUS      := $(shell grep -r -l -F '\begin[snippet]' CodeSamples)
 SOURCES_OF_LTMS        := $(patsubst %.litmus,%.ltms,$(SOURCES_OF_LITMUS))
@@ -202,6 +205,18 @@ endif
 		echo "Substitute 'fcvref' for 'lineref' in $(LINEREF_ENV)." ; \
 		exit 1 ; \
 	fi
+	@if [ ! -z "$(CREFPAIR)" -a "$(CREFPAIR)" != " " ]; then \
+		echo "------" ; \
+		if grep -q -E $(CREFPTN) $(CREFPAIR) ; then \
+			grep -n -B 2 -A 2 -E $(CREFPTN) $(CREFPAIR) ; \
+		else \
+			grep -zo -B 2 -A 2 -E $(CREFPTN) $(CREFPAIR) ; \
+			echo ; \
+		fi ; \
+		echo "------" ; \
+		echo "Need to use \[Cc]refrange or \[Cc]lnrefrangein $(CREFPAIR)." ; \
+		exit 1 ; \
+	fi
 	echo > qqz.tex
 	echo > contrib.tex
 	echo > origpub.tex
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v2] Makefile: Add check of \crefrange and \clnrefrange misuse

Quoted 25 lines · Akira Yokosawa
Quoted 1 line

From f445ac887a125bbff303b80921f981ea0704c748 Mon Sep 17 00:00:00 2001

From: Akira Yokosawa <[email protected]>
Date: Sat, 15 Feb 2020 08:36:53 +0900
Subject: [PATCH v2] Makefile: Add check of \crefrange and \clnrefrange misuse

To prevent typos simillar to the one fixed in commit b3b06a98bb7c ("datastruct.tex: fix some minor typos") to happen again, add checks to detect the following patterns of misuses:

... \cref{label A}{label B} ...

... \cref{long label X}
{another long label Y}

In the formar case, counts of violating lines are presented in the error message.
In the latter case, only the file name can be presented due to the "-zo" option to enable multi-line pattern search.

Note: There can be false negatives in the check.
For example, it can't not detect:

... \cref{label E}% some comment
{label F}

Quoted 7 lines

, at the moment.

---
Hi Paul,

This one uses a regex to cover both \cref and \clnref pattern.

Queued and pushed, thank you!

Thanx, Paul

Quoted 42 lines

Thanks, Akira
--

 Makefile | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
Makefile +15 -0
index ccc840be..7d1ec630 100644
@@ -131,6 +131,9 @@ LINEREF_ENV_END     := $(shell grep -l -F '\end{lineref}'     $(LATEXSOURCES))
 LINELABEL_ENV := $(sort $(LINELABEL_ENV_BEGIN) $(LINELABEL_ENV_END))
 LINEREF_ENV   := $(sort $(LINEREF_ENV_BEGIN) $(LINEREF_ENV_END))
 
+CREFPTN    := '\\[Cc](ln)?ref{[^{]+}\s*{[^}]+}'
+CREFPAIR   := $(shell grep -l -zo -E $(CREFPTN)   $(LATEXSOURCES))
+
 SOURCES_OF_SNIPPET_ALL := $(shell grep -r -l -F '\begin{snippet}' CodeSamples)
 SOURCES_OF_LITMUS      := $(shell grep -r -l -F '\begin[snippet]' CodeSamples)
 SOURCES_OF_LTMS        := $(patsubst %.litmus,%.ltms,$(SOURCES_OF_LITMUS))
@@ -202,6 +205,18 @@ endif
 		echo "Substitute 'fcvref' for 'lineref' in $(LINEREF_ENV)." ; \
 		exit 1 ; \
 	fi
+	@if [ ! -z "$(CREFPAIR)" -a "$(CREFPAIR)" != " " ]; then \
+		echo "------" ; \
+		if grep -q -E $(CREFPTN) $(CREFPAIR) ; then \
+			grep -n -B 2 -A 2 -E $(CREFPTN) $(CREFPAIR) ; \
+		else \
+			grep -zo -B 2 -A 2 -E $(CREFPTN) $(CREFPAIR) ; \
+			echo ; \
+		fi ; \
+		echo "------" ; \
+		echo "Need to use \[Cc]refrange or \[Cc]lnrefrangein $(CREFPAIR)." ; \
+		exit 1 ; \
+	fi
 	echo > qqz.tex
 	echo > contrib.tex
 	echo > origpub.tex
Signature · 1 line
2.17.1