>From c0b6af552c7d5ade1b721ba4d6bd3c42e0f913e1 Mon Sep 17 00:00:00 2001 From: Akira Yokosawa <akiyks@xxxxxxxxx> 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. Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx> --- Makefile | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Makefile b/Makefile index ccc840be..cb9ef668 100644 --- a/Makefile +++ b/Makefile @@ -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 -- 2.17.1