Skip to contentSkip to conversation

Quick Quiz layout update

PATCH In review Akira Yokosawa 2 participants 5 messages Jan 9, 2017 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Quick Quiz layout update

From 6da1b01ee71e53c559a73e20686eabe67ba23935 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Mon, 9 Jan 2017 23:09:24 +0900
Subject: [PATCH 0/3] Quick Quiz layout update

Hi Paul,

This patch set improves layout of Appendix "Answers to Quick Quizzes". White boxes at the end of answers sometimes become "orphans". This happens when an answer finishes with an "enumerate" or "figure" environment. As an end of these environments is treated as a page/column break candidate, a white box just after the end of an environment tends to become an orphan (single symbol at the top of next page/column).

To prevent this, white boxes can be moved to just after the final item of "enumerate" environments. Or they can be moved to just after the final paragraph before "figure" environments.

I wrote a script to do this (Patch 1), and incorporated it into the rule of target "qqz.tex" (Patch 2). Patch 3 tweaks vertical space parameters for a better look of the Appendix

Thanks, Akira
--
Akira Yokosawa (3):
qqz: Add script to reorder lines in qqz.tex
Makefile: Use qqzreorder.pl in qqz.tex target qqz.sty: Tweak \vspace{} parameter

 Makefile                |  2 +-
 qqz.sty                 |  6 ++--
 utilities/qqzreorder.pl | 88 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+), 4 deletions(-)
 create mode 100644 utilities/qqzreorder.pl
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/3 qqz: Add script to reorder lines in qqz.tex

From fadc8d4c0b240dd49570a60b627a6e81256d511f Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Mon, 9 Jan 2017 18:04:24 +0900
Subject: [PATCH 1/3] qqz: Add script to reorder lines in qqz.tex

This script moves some \QuickE{} to prevent white boxes from becoming widows at the end of Answers which finish with an "enumerate" or "figure" environment.

Excerpt of diff by this script is as follows:

@@ -2468,8 +2468,8 @@
and~\ref{chp:Deferred Processing}.
\item The polling loops result in poor energy efficiency.
An event-driven design is preferable.
- \end{enumerate}
\QuickE{}
+ \end{enumerate}
\QuickQ{}
On the \path{count_stat.c} row of
Table~\ref{tab:count:Statistical Counter Performance on Power-6},
@@ -4527,6 +4527,7 @@
\co{synchronize_sched()} with \co{synchronize_rcu()},
perhaps as shown in
Figure~\ref{fig:defer:Using RCU to Wait for Mythical Preemptible NMIs to Finish}.
+\QuickE{}
%
\begin{figure}[tb]
{\scriptsize
@@ -4573,7 +4574,6 @@
\label{fig:defer:Using RCU to Wait for Mythical Preemptible NMIs to Finish} \end{figure}
%
-\QuickE{}
\QuickQ{}
Why do some of the cells in
Table~\ref{tab:defer:RCU Wait-to-Finish APIs}

---
 utilities/qqzreorder.pl | 88 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
 create mode 100644 utilities/qqzreorder.pl
utilities/qqzreorder.pl new file +88 -0
new file mode 100644
index 0000000..197d5a0
@@ -0,0 +1,88 @@
+#!/usr/bin/perl
+#
+# Move line of \QuickE{} below \end{enumerate} to just above
+# the \end{enumerate}.
+# Move line of \QuickE{} below \end{figure} to above
+# \begin{figure} corresponding to it.
+#
+# 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, 2017
+#
+# Authors: Akira Yokosawa <[email protected]>
+
+my $line;
+my $after_end_enum = 0;
+my $in_figure = 0;
+my $after_figure = 0;
+my $line_idx = 1;
+my @line_buf;
+
+$line_buf[1] = <>;
+while($line = <>) {
+    if ($after_end_enum) {
+	if ($line =~ /\\QuickE\{\}/) {
+	    print $line;
+	} else {
+	    print $line_buf[1];
+	    $line_buf[1] = $line;
+	}
+	$after_end_enum = 0;
+	next;
+    }
+    if ($in_figure) {
+	if ($line =~ /\\end\{figure\}/) {
+	    $after_figure = 1;
+	    $in_figure = 0;
+	}
+	$line_buf[++$line_idx] = $line;
+	next;
+    }
+    if ($after_figure) {
+	if ($line =~ /%/) {
+	    $line_buf[++$line_idx] = $line;
+	    next;
+	}
+	if ($line =~ /\\QuickE\{\}/) {
+	    print $line;
+	    for my $i (1 .. $line_idx-1) {
+		print $line_buf[$i];
+	    }
+	    $line_buf[1] = $line_buf[$line_idx];
+	} else {
+	    for my $i (1 .. $line_idx) {
+		print $line_buf[$i];
+	    }
+	    $line_buf[1] = $line;
+	}
+	$line_idx = 1;
+	$after_figure = 0;
+	next;
+    }
+    if ($line =~ /\\end\{enumerate\}/) {
+	print $line_buf[1];
+	$line_buf[1] = $line;
+	$after_end_enum = 1;
+	next;
+    }
+    if ($line =~ /\\begin\{figure\}/) {
+	$in_figure = 1;
+	$line_buf[++$line_idx] = $line;
+	next;
+    }
+    print $line_buf[1];
+    $line_buf[1] = $line;
+}
+print $line_buf[1];
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/3 Makefile: Use qqzreorder.pl in qqz.tex target

In reply to Akira Yokosawa

From 36a6809e32a47baf16e8ebe8922e7e05caa6a083 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Mon, 9 Jan 2017 18:29:59 +0900
Subject: [PATCH 2/3] Makefile: Use qqzreorder.pl in qqz.tex target

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 9a2e118..e953842 100644
@@ -92,7 +92,7 @@ perfbook_flat.tex: perfbook.tex $(LATEXSOURCES) $(PDFTARGETS_OF_EPS) $(PDFTARGET
 	texexpand perfbook.tex > $@
 
 qqz.tex: perfbook_flat.tex
-	sh utilities/extractqqz.sh < $< > $@
+	sh utilities/extractqqz.sh < $< | perl utilities/qqzreorder.pl > $@
 
 contrib.tex: perfbook_flat.tex qqz.tex
 	cat $^ | sh utilities/extractcontrib.sh > $@
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/3 qqz.sty: Tweak \vspace{} parameter

In reply to Akira Yokosawa

From 6da1b01ee71e53c559a73e20686eabe67ba23935 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Mon, 9 Jan 2017 20:29:45 +0900
Subject: [PATCH 3/3] qqz.sty: Tweak \vspace{} parameter

Reduce \vspace{} parameters after black and white boxes in Answers to Quick Quizzes for a denser layout. Also add glue parameters to permit more flexible typeset.

---
 qqz.sty | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
qqz.sty +3 -3
index dda1c17..317e809 100644
@@ -13,7 +13,7 @@
 %%
 %% Copyright (C) IBM Corporation, 2008
 %% Copyright (C) Paolo Bonzini, 2015
-%% Copyright (C) Akira Yokosawa, 2016
+%% Copyright (C) Akira Yokosawa, 2016, 2017
 %%
 %% Authors: Paul E. McKenney <[email protected]>
 %%          Paolo Bonzini <[email protected]> # cross-link questions and answers
@@ -84,11 +84,11 @@
 
 \newcommand{\QuickA}[1]{%
 	\hyperref[QQ.\QuickQuizAnswerChapter.\thequickquizctrC]{\rule{7pt}{7pt}}
-	\par\vspace{0.8\baselineskip}
+	\par\vspace{0.5\baselineskip plus .5ex minus .3ex}
 	\noindent\textbf{Answer:} \\ }
 
 \newcommand{\QuickE}{%
 	\hyperref[QQE.\QuickQuizAnswerChapter.\thequickquizctrC]{\ding{113}}
-	\vspace{1.5\baselineskip}
+	\vspace{1.0\baselineskip plus 2ex minus .5ex}
 }
 
Signature · 1 line
2.7.4
#4 lore raw
In reply to Akira Yokosawa
Quoted 14 lines · Akira Yokosawa
Quoted 1 line

From 6da1b01ee71e53c559a73e20686eabe67ba23935 Mon Sep 17 00:00:00 2001

From: Akira Yokosawa <[email protected]>
Date: Mon, 9 Jan 2017 23:09:24 +0900
Subject: [PATCH 0/3] Quick Quiz layout update

Hi Paul,

This patch set improves layout of Appendix "Answers to Quick Quizzes". White boxes at the end of answers sometimes become "orphans". This happens when an answer finishes with an "enumerate" or "figure" environment. As an end of these environments is treated as a page/column break candidate, a white box just after the end of an environment tends to become an orphan (single symbol at the top of next page/column).

Quoted 7 lines

To prevent this, white boxes can be moved to just after the final item of "enumerate" environments. Or they can be moved to just after the final paragraph before "figure" environments.

I wrote a script to do this (Patch 1), and incorporated it into the rule of target "qqz.tex" (Patch 2). Patch 3 tweaks vertical space parameters for a better look of the Appendix

I queued this and pushed it, let's see what people think. It does make the answers ending in a list look better, though I am wondering whether ending an answer with a list is the right thing for me to be doing. ;-)

Thanx, Paul

Quoted 16 lines

Thanks, Akira
--
Akira Yokosawa (3):
qqz: Add script to reorder lines in qqz.tex
Makefile: Use qqzreorder.pl in qqz.tex target qqz.sty: Tweak \vspace{} parameter

 Makefile                |  2 +-
 qqz.sty                 |  6 ++--
 utilities/qqzreorder.pl | 88 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+), 4 deletions(-)
 create mode 100644 utilities/qqzreorder.pl
Signature · 1 line
2.7.4