From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from scc-mailout-kit-02.scc.kit.edu (scc-mailout-kit-02.scc.kit.edu [129.13.231.82]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTP id 3fa864a0 for ; Sun, 17 Apr 2016 11:55:33 -0500 (EST) Received: from asta-nat.asta.uni-karlsruhe.de ([172.22.63.82] helo=hekate.usta.de) by scc-mailout-kit-02.scc.kit.edu with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (envelope-from ) id 1arpyt-0002uh-55; Sun, 17 Apr 2016 18:55:33 +0200 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.77) (envelope-from ) id 1arpys-0002O1-Od; Sun, 17 Apr 2016 18:55:30 +0200 Received: from athene.usta.de ([172.24.96.10]) by donnerwolke.usta.de with esmtp (Exim 4.84_2) (envelope-from ) id 1arpys-0003Ec-Jq; Sun, 17 Apr 2016 18:55:30 +0200 Received: from localhost (athene.usta.de [local]) by athene.usta.de (OpenSMTPD) with ESMTPA id e592e77e; Sun, 17 Apr 2016 18:55:30 +0200 (CEST) Date: Sun, 17 Apr 2016 18:55:30 +0200 From: Ingo Schwarze To: discuss@mdocml.bsd.lv Cc: wblock@FreeBSD.org Subject: Re: Escaping preference Message-ID: <20160417165530.GC22859@athene.usta.de> References: X-Mailinglist: mdocml-discuss Reply-To: discuss@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) 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