groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question - Indents and paragraph filling


From: G. Branden Robinson
Subject: Re: Newbie question - Indents and paragraph filling
Date: Mon, 17 Apr 2023 02:20:33 -0500

Hi Ben,

At 2023-04-15T14:38:56+0200, Ben wrote:
> I am by no means an experienced user of groff. I thought I would give
> it a go as it may be useful for setting exams and test papers in my
> classroom.  The exam class in latex is amazing but I am looking for
> greater control over what is happening on the page. I love the
> simplicity of unix and groff and was hoping to ask for some help with
> a macro which I could use for setting questions.
> 
> I was looking to insert a question Num and then without a break indent
> the question text. Similar to the IP command with a bullet, however, I
> wish to append an additional mark allocation to the end of this body
> text also without a break. See screenshot below.

> I have played around with page offset and line length. I also
> attempted to build an \hfill(latex like) macro which was way above my
> level of skill. I am starting to get my head around breaks and new
> lines of input and output but I am missing a key piece.
> 
> I see it as something like this.
> 
>    1.  print a question number , do not break (eg 1. or 1) perhaps use a
>    'br or \c to enforce this non break

'br does nothing.  The ' control character means "suppress an initial
break caused by the request", and since that is all `br` does, nothing
remains.

>    2. adjust margin using the .in +0.5i command or the .po and .ll
>    command

It's important to distinguish the page offset from the indentation
amount.  The indentation counts as part of the output line length and
the page offset does not.

For instance, on 8½-inch wide U.S. letter paper, we might use a page
offset of one inch and a line length of 6½ inches.  That gives us 1-inch
"margins" on the left and right sides of the page.  "Indentation" is
something we use to organize text _within_ our page margins.

.\" assuming U.S. letter paper
.po 1i
.ll 6.5i
.ti 5n \" set up a temporary indent (affects only the next output line)
Hello, world!
Sed ut perspiciatis,
unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium,
totam rem aperiam eaque ipsa,
quae ab illo inventore veritatis et quasi architecto beatae vitae dicta
sunt,
explicabo.
.sp \" break the line (and paragraph)
.\" Now set a block quote.
.in +2i
.ll -2i
Nemo enim ipsam voluptatem,
quia voluptas sit,
aspernatur aut odit aut fugit,
sed quia consequuntur magni dolores eos,
qui ratione voluptatem sequi nesciunt,
neque porro quisquam est,
qui dolorem ipsum,
quia dolor sit amet consectetur adipiscivelit,
sed quia non-numquam eius modi tempora incidunt,
ut labore et dolore magnam aliquam quaerat voluptatem.
.sp
.\" unwind our changes
.in -2i
.ll +2i
Goodbye!

When I format the foregoing, here's what I get.

$ nroff -Tascii ATTIC/ipsum.troff
               Hello,  world!   Sed  ut perspiciatis, unde omnis iste natus
          error sit voluptatem accusantium doloremque laudantium, totam rem
          aperiam eaque ipsa, quae ab illo inventore veritatis et quasi ar-
          chitecto beatae vitae dicta sunt, explicabo.

                              Nemo  enim  ipsam  volup-
                              tatem, quia voluptas sit,
                              aspernatur aut  odit  aut
                              fugit,  sed quia consequ-
                              untur magni dolores  eos,
                              qui   ratione  voluptatem
                              sequi   nesciunt,   neque
                              porro  quisquam  est, qui
                              dolorem ipsum, quia dolor
                              sit    amet   consectetur
                              adipiscivelit,  sed  quia
                              non-numquam   eius   modi
                              tempora incidunt, ut  la-
                              bore   et  dolore  magnam
                              aliquam  quaerat   volup-
                              tatem.

          Goodbye!

(I've trimmed the blank lines that fill out the 66-line page.)

>    3. fill text within these margins, do not break, kinda like a block quote
>    4. Adjust margin back, do not break, another \c or 'br
>    5. Append mark allocation (12 marks)
>    6. end macro
> 
> Any help would be much appreciated. I would prefer ..read x part of
> the Ffing manual more carefully rather than paste in code I do not
> really understand.

Well, I'll tell you what I would do, which will include an exhibit, but
also a reference to documentation.

Because you need 2 different pieces of marginalia (so to speak), you
effectively have three columns of layout, and moreover I expect you
don't want the sizes of those columns to drift throughout the document,
or "adapt" to their contents.

Any time you need more than two columns in a *roff document, I think
it's wise to consider the tbl(1) preprocessor.

Here is my solution.  It does not use any macro package (like ms(7)), as
you didn't express an interest in any.

.fam H \" Helvetica
.\" Define some strings to represent common unit combinations.
.\" If you get much more sophisticated than this, it's probably time to
.\" bust out eqn(1) and use inline equations in your tables.
.ds ms-1 m\[md]s\v'-0.3m'\s[-2]\-1\s[0]\v'0.3m'
.ds ms-2 m\[md]s\v'-0.3m'\s[-2]\-2\s[0]\v'0.3m'
.TS
tab(@);
Lw(4n)t Lx Lw(4n)d
^       ^  ^.
2.2@T{
Helen and Matthew are riding their scooters.
Matthew is at rest when Helen passes him moving at a constant speed of
0.37\~\*[ms-1] going in a straight line.
After 1.8\~s,
Matthew decides to chase Helen and try and catch her.
Matthew accelerates at 0.91\~\*[ms-2].
How much time does Helen have from the moment she passed Matthew until
Matthew is side by side with her?
T}@(7)
@\&@
.TE

There's only one aspect of the above that I consider a "trick", and that
is the construction of a seemingly gratuitous row of vertically spanned
entries (and then a row with a dummy entry `\&` to use it).  I did this
because the 't' and 'd' modifiers change the vertical alignment of table
entries only within _spanned_ areas.  Without this expediency, the value
in the right column (the point value of the exam question, I assume)
stayed at the top of its table cell instead of being placed at the
bottom as your sample image illustrated.

This example renders the same with both groff 1.22.4 and groff Git (soon
to be groff 1.23.0), but for 1.23 I have rewritten the tbl(1) man page
to, in my opinion, make it more comprehensive and descriptive of the
behavior of the preprocessor.  (To date I haven't gotten much feedback
on it, positive or negative.  Maybe it puts people to sleep before they
get very far...)

I mention this because if you want to look up how this example works, I
think the new tbl(1) man page is a much better resource.

I'm attaching the rendered output of the groff input above, and of the
tbl(1) man page in case you think it will suit your needs.

Please follow up if you need assistance generalizing this solution to n
exam questions.  The vertical span trick will require that you start a
new table format (identical to the old one) with `.T&`, or you could
have a series of table _regions_ (areas between `.TS` and `.TE`).  These
approaches could be mixed, for instance if you needed a paragraph to
interrupt the question series to announce a non-calculator portion, or
introduce a bunch of invariants that apply to the next m problems, and
so on.

If you truly want to tackle this without recourse to preprocessing, it
will be worth your while to learn about traps, and the `mk` and `rt`
requests.  Try the following Dropbox URL:

https://www.dropbox.com/sh/17ftu3z31couf07/AAC_9kq0ZA-Ra2ZhmZFWlLuva?dl=0

...navigate into the "1.23.0.rc4" folder, open the file
groff.2023-04-16.pdf, then start(!) with section 5.27, "Deferring
Output".  The next section and subsection, "Traps" and "Vertical
Position Traps", will require your attention.  Section 5.25, "Page
Motions", discusses the aforementioned `mk` and `rt` requests.

This Dropbox folder will be rearranged and updated from time to time
since its capacity is not unlimited, so you might want to download that
copy manual while it is available.  (It is also available in the groff
1.23.0.rc4 distribution archive[1] as "doc/groff.pdf", and that resource
should remain online for quite some time.)

Regards,
Branden

[1] https://alpha.gnu.org/gnu/groff/groff-1.23.0.rc4.tar.gz

Attachment: exam.ps
Description: PostScript document

Attachment: tbl.pdf
Description: Adobe PDF document

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]