Re: Groff examples repository

2021-08-29 Thread Heinz-Jürgen Oertel
Am Mittwoch, 25. August 2021, 18:50:56 CEST schrieb Thomas Dupond:
> 
> 
> As noted on the first page, feel free to email me any macro you find
> interesting, I will put it online as soon as I can :) .


Hi,

in the past for technical papers I often used dformat:

https://noxz.tech/guides/groff/papers/dformat_--_a_program_for_typesetting_data_formats__142.pdf


extracted the source from this paper, but it can be found now at 

https://github.com/sathlan/dformat

Unfortunately it does not contain the changes I did to use gpic "shaded" 
command to use Colored Objects


Regards
Heinz








Re: Groff examples repository

2021-08-29 Thread G. Branden Robinson
At 2021-08-28T12:14:17-0400, Douglas McIlroy wrote:
> -
> 
> A small anomaly. Consider
> 
> .de .
> .tm Hi
> ,..
> ..
> 
> The second .. emits "Hi". This fragment also emits "Hi":
> 
> .de end end
> .tm Hi
> .end
> 
> But this (with macro . not previously defined)
> does not:
> 
> .de . .
> .tm Hi
> ..

I used the same example last week to update the "Writing Macros" section
of our Texinfo manual.  The concept of "copy mode" confused me deeply
when I first arrived in the groff community and finally I realized that
the statement, used repeatedly about escapes in our documentation, that
certain ones are "interpreted in copy mode" makes a lot more sense to
people who already know what copy mode is than those who don't.
Recasting ensued.

I have added some of this material to groff(7) as well, albeit in
aggressively condensed form and with no examples.

It may go without saying, but I have some minor revisions to the below
queued already.  Nevertheless I think in its present state it renders
the subject more accessible.

*** SNIP ***
5.21 Writing Macros
===

A "macro" is a stored collection of text and control lines that can be
used multiple times.  Use macros to define common operations.  *Note
Strings::, for a (limited) alternative syntax to call macros.  While
requests exist for the purpose of creating macros, simply calling an
undefined macro, or interpolating it as a string, will cause it to be
defined as empty.  *Note Identifiers::.

 -- Request: .de name [end]
 Define a macro NAME, replacing the definition of any existing
 request, macro, string, or diversion called NAME.  GNU 'troff'
 enters "copy mode", storing subsequent input lines in an internal
 buffer.  If the optional second argument is not specified, the
 macro definition ends with the control line '..' (two dots).
 Alternatively, END identifies a macro whose call syntax ends the
 definition of NAME; END is then called normally.  Spaces or tabs
 are permitted after the control character in the line containing
 this ending token (either '.' or 'END'), but a tab immediately
 after the token prevents its recognition as the end of a macro
 definition.(1)  (*note Writing Macros-Footnote-1::)

 Here is a small example macro called 'P' that causes a break and
 inserts some vertical space.  It could be used to separate
 paragraphs.

  .de P
  .  br
  .  sp .8v
  ..

 We can define one macro within another.  Attempting to nest '..'
 naïvely will end the outer definition because the inner definition
 isn't interpreted as such until the outer macro is later
 interpolated.  We can use an end macro instead.  Each level of
 nesting should use a unique end macro.

 An end macro need not be defined until it is called.  This fact
 enables a nested macro definition to begin inside one macro and end
 inside another.  Consider the following example.(2)  (*note Writing
 Macros-Footnote-2::)

  .de m1
  .  de m2 m3
  you
  ..
  .de m3
  Hello,
  Joe.
  ..
  .de m4
  do
  ..
  .m1
  know?
  .  m3
  What
  .m4
  .m2
  => Hello, Joe.  What do you know?

 A nested macro definition _can_ be terminated with '..', and nested
 macros _can_ reuse end macros, but these control lines must be
 escaped multiple times for each level of nesting.  The necessity of
 this escaping and the utility of nested macro definitions will
 become clearer when we employ macro parameters and consider the
 behavior of copy mode in detail.

 -- Request: .de1 name [end]
 The 'de1' request defines a macro that executes with compatibility
 mode disabled (*note Implementation Differences::).  On entry, the
 state of compatibility mode enablement is saved, and on exit it is
 restored.  Observe the extra backlash before the interpolation of
 register 'xxx'; we'll explore this subject in *note Copy Mode::.

  .nr xxx 12345
  .de aa
  The value of xxx is \\n[xxx].
  .  br
  ..
  .de1 bb
  The value of xxx is \\n[xxx].
  ..
  .cp 1
  .aa
  error-> warning: register '[' not defined
  => The value of xxx is 0xxx].
  .bb
  => The value of xxx is 12345.

 -- Request: .dei name [end]
 -- Request: .dei1 name [end]
 The 'dei' request defines a macro indirectly.  That is, it
 interpolates strings named NAME and END before performing the
 definition.

 The following examples are equivalent.

  .ds xx aa
  .ds yy bb
  .dei xx yy

  .de aa bb

 The 'dei1' request is similar to 'dei', but with compatibility mode
 

Re: Groff examples repository

2021-08-29 Thread Keith Marshall
On 28/08/2021 17:14, Douglas McIlroy wrote:
> A small anomaly. Consider
> 
> .de .
> .tm Hi
> ,..
> ..

I'm guessing that the comma, before the first ".." is an unintended
introduction?

> The second .. emits "Hi". This fragment also emits "Hi":
> 
> .de end end
> .tm Hi
> .end
> 
> But this (with macro . not previously defined)
> does not:
> 
> .de . .
> .tm Hi
> ..

Even if macro "." were previously defined, the latter should not emit
"Hi".  Footnote 16, in reference to ".de" and its variations, within the
groff reference manual[1], explains this, (with an essentially similar
example): during a macro definition, '..' is never handled as a call to
'.', even if you say '.de foo .' explicitly.

[1]: https://www.gnu.org/software/groff/manual/groff.pdf

(FWIW, I think I would have s/handled/interpreted/)

-- 
Cheers, Keith



Re: Groff examples repository

2021-08-29 Thread Dave Kemper
On 8/25/21, Thomas Dupond  wrote:
> The Groff examples repository is now available on the web at
> https://froude.eu/groff and on geminispace at gemini://froude.eu/groff

Fantastic!  Thanks so much for putting this together.

I see that each page has a link to the source mailing list post, so
that the original contributor can be identified.  But for pages with
code that has a specific author (not all the pages fall into this
category), I wonder if the author ought to be credited on the
repository page itself as well.



Re: Groff examples repository

2021-08-29 Thread Ingo Schwarze
Hi Thomas,

On 8/25/21, Thomas Dupond  wrote:

> The Groff examples repository is now available on the web at
> https://froude.eu/groff and on geminispace at gemini://froude.eu/groff

Nice.

I added a link to it to

  https://mandoc.bsd.lv/links.html

I think on your start page, you ought to add a link to

  https://www.gnu.org/software/groff/ .

Since John Gardner will (rightly) insist that examples of mdoc(7)
code are nothing more than mere examples of roff(7) code, i would
consider a link to

  https://mandoc.bsd.lv/mdoc/

useful as well; your call.

If you want to add a full-blown example of how to use groff to
set up a complete conference presentation, feel free to link to

  https://www.openbsd.org/papers/eurobsdcon2018-mandoc.roff
  https://www.openbsd.org/papers/eurobsdcon2018-mandoc.pdf

Parts of the contents of that presentation are also loosely related
to roff(7), but that is incidental.  The point why it might matter
here really is the full-blown example of setting up complete slides
for a conference presentation.

Yours,
  Ingo



Re: Groff examples repository

2021-08-29 Thread Ingo Schwarze
Hi Thomas,

sorry for the afterthought...

Ingo Schwarze wrote on Sun, Aug 29, 2021 at 07:34:56PM +0200:

>   https://mandoc.bsd.lv/mdoc/

Even if you consider mdoc(7) off-topic, you definitely want to link
to these two pages:

  https://mandoc.bsd.lv/mdoc/details/recursion.html
  https://mandoc.bsd.lv/mdoc/details/redefine_self.mdoc

You think that is insane?

Well, i can't really disagree with you.  :-)


Then again, if a programming language can be used to print Fibonacci
numbers, that *is* useful, don't you think?

 $ man -cl redefine_self.mdoc
()()

1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584

  ()

Yours,
  Ingo



Re: Groff examples repository

2021-08-29 Thread Thomas Dupond
Heinz-Jürgen Oertel  wrote:

> Hi,
>
> in the past for technical papers I often used dformat:
>
> https://noxz.tech/guides/groff/papers/dformat_--_a_program_for_typesetting_data_formats__142.pdf

This is excellent, I'm always impressed by what can be achieved with
groff and pic.

> extracted the source from this paper, but it can be found now at
>
> https://github.com/sathlan/dformat
>
> Unfortunately it does not contain the changes I did to use gpic
> "shaded" command to use Colored Objects

Would you mind sharing your changes so I can include them?
>
> Regards
>   Heinz

The DFORMAT program is now listed on the website at
https://froude.eu/groff/examples/dformat.html and on gemini at
gemini://froude.eu/groff/examples/dformat.gmi

Regards,

Thomas




Re: Groff examples repository

2021-08-29 Thread Heinz-Jürgen Oertel
Am Sonntag, 29. August 2021, 22:46:54 CEST schrieb Thomas Dupond:
> Heinz-Jürgen Oertel  wrote:
> 
> > Hi,
> >
> > in the past for technical papers I often used dformat:
> >
> > https://noxz.tech/guides/groff/papers/dformat_--_a_program_for_typesetting_data_formats__142.pdf
> 
> This is excellent, I'm always impressed by what can be achieved with
> groff and pic.
> 
> > extracted the source from this paper, but it can be found now at
> >
> > https://github.com/sathlan/dformat
> >
> > Unfortunately it does not contain the changes I did to use gpic
> > "shaded" command to use Colored Objects
> 
> Would you mind sharing your changes so I can include them?


may be it will be better to incorporate it int the github project mentioned 
above. 

attached a small example illustrating it.

> >
> > Regards
> > Heinz
> 
> The DFORMAT program is now listed on the website at
> https://froude.eu/groff/examples/dformat.html and on gemini at
> gemini://froude.eu/groff/examples/dformat.gmi
> 
> Regards,
> 
> Thomas

Thanks Thomas

Heinz


example.pdf
Description: Adobe PDF document


Re: Groff examples repository

2021-08-29 Thread John Gardner
>
> Since John Gardner will (rightly) insist that examples of mdoc(7) code are
> nothing more than mere examples of roff(7) code


To quote Heisenberg: *"You're goddamn right."* ;-)

The Groff examples repository is now available on the web at
> https://froude.eu/groff
>

Feel free to plunder my stupid macro package for anything you consider
worth sharing:

https://github.com/Alhadis/Mono

When copy+pasting from the macro package, be aware that many internal
registers and strings use names containing ASCII control characters, which
mightn't be visible in your browser/editor. Specifically, ^B, ^C, ^E, ^F, ^G,
^?.

On Mon, 30 Aug 2021 at 03:36, Ingo Schwarze  wrote:

> Hi Thomas,
>
> On 8/25/21, Thomas Dupond  wrote:
>
> > The Groff examples repository is now available on the web at
> > https://froude.eu/groff and on geminispace at gemini://froude.eu/groff
>
> Nice.
>
> I added a link to it to
>
>   https://mandoc.bsd.lv/links.html
>
> I think on your start page, you ought to add a link to
>
>   https://www.gnu.org/software/groff/ .
>
> Since John Gardner will (rightly) insist that examples of mdoc(7)
> code are nothing more than mere examples of roff(7) code, i would
> consider a link to
>
>   https://mandoc.bsd.lv/mdoc/
>
> useful as well; your call.
>
> If you want to add a full-blown example of how to use groff to
> set up a complete conference presentation, feel free to link to
>
>   https://www.openbsd.org/papers/eurobsdcon2018-mandoc.roff
>   https://www.openbsd.org/papers/eurobsdcon2018-mandoc.pdf
>
> Parts of the contents of that presentation are also loosely related
> to roff(7), but that is incidental.  The point why it might matter
> here really is the full-blown example of setting up complete slides
> for a conference presentation.
>
> Yours,
>   Ingo
>
>