discuss@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: discuss@mdocml.bsd.lv
Cc: wblock@FreeBSD.org
Subject: Re: Escaping preference
Date: Sun, 17 Apr 2016 18:55:30 +0200	[thread overview]
Message-ID: <20160417165530.GC22859@athene.usta.de> (raw)
In-Reply-To: <alpine.BSF.2.20.1604170954030.30232@wonkity.com>

Hi Warren,

Warren Block wrote on Sun, Apr 17, 2016 at 10:20:23AM -0600:

> Just had a bug reported where "\n" used in code examples
> was not escaped and so renders improperly.
> 
>   printf("Bad input\n");
> 
> renders as
> 
>   printf("Bad input0);
> 
> on both FreeBSD 10 and 11 (groff and mandoc, respectively).

Indeed, that must be escaped.

The escape sequence '\n' interpolates a number register.
Specifically, '\n"' interpolates the number register with
the name '"'.  Since that number register will usually not
exist, it renders as '0'.  See roff(7), ESCAPE SEQUENCE
REFERENCE.  So the rendering is correct.

> https://www.freebsd.org/cgi/man.cgi?query=lsearch
> 
> Both of these escaped forms renders properly:
> 
>   printf("Bad input\\n");

NEVER use "\\" in manual pages.  It is *very* wrong.  Basically,
the "\\" escape sequence is only needed when implementing roff(7)
macro sets, that is, when writing macro definitions for macros that
take arguments.  Its purpose is to delay escape sequence expansion
- which sounds about as arcane as it indeed is.

But in the case at hand, you don't want to merely delay expansion
of "\n", you don't want "\n" at all.

>   printf("Bad input\en");

That's right.

> \e is recommended in Escaping Special Characters in mdoc(7) (really
> groff_mdoc(7)) on FreeBSD 10, not mentioned in mandoc's mdoc(7) on
> FreeBSD 11.

It's not specific to mdoc(7), but a basic roff(7) feature common
to any and all macro languages.  It is documented
 - in mandoc_char(7), subsection "Backslashes",
 - in roff(7), section LANGUAGE SYNTAX subsection "Special Characters"
 - in roff(7), section ESCAPE SEQUENCE REFERENCE subsection "\e".
 - in roff(7), section REQUEST REFERENCE subsection "de"
 - in roff(7), section MACRO SYNTAX,

> The double backslash appears preferable to me, more recognizable
> for people who might not be familiar with mdoc markup.  Is there
> any reason to prefer the \e version?

There is no guarantee that "\\" will work at all.  I may break
horribly in some contexts with some roff(7) implementations.  It
is among the roff(7) features hardest to understand and hardest to
predict what they may do.

Yours,
  Ingo
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

      reply	other threads:[~2016-04-17 16:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-17 16:20 Warren Block
2016-04-17 16:55 ` Ingo Schwarze [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160417165530.GC22859@athene.usta.de \
    --to=schwarze@usta.de \
    --cc=discuss@mdocml.bsd.lv \
    --cc=wblock@FreeBSD.org \
    --subject='Re: Escaping preference' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).