groff
[Top][All Lists]
Advanced

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

Re: .CW usage by a new user


From: Russ Allbery
Subject: Re: .CW usage by a new user
Date: Thu, 05 Sep 2024 09:41:35 -0700
User-agent: Gnus/5.13 (Gnus v5.13)

"isf (Jordán)" <isf@member.fsf.org> writes:

> Thanks, but what if I want do something like this:

> .CW "$ echo "foo    bar""

> Because the output is something like this:

> bar"$ echo foo

> When I want something like this in the PDF.

> $ echo "foo    bar"

It may help to go through this step by step, or at least that's the way
that I think about it (probably because I mostly write code to generate
*roff rather than write it directly).

Please note that all the intermediate steps here are, by themselves,
invalid, and are just being shown as steps in the process.  Only the final
step is the correct input.

You want that string to all be in a fixed-width font.  So to start with,
you put .CW in front of it:

.CW $ echo "foo   bar"

But the .CW macro takes a single argument and without any surrounding
quotes that argument is going to end with the first space, so you need to
enclose the entire argument in double quotes so that it's one argument:

.CW "$ echo "foo   bar""

Now you have the problem that the interior double quotes that should be
part of the argument are going to be interpreted as ending the quoted
string that comprises the argument.  All of those double quotes inside the
quoted argument have to be escaped.  The way to do that is to replace each
interior double quote with two consecutive double quotes:

.CW "$ echo ""foo  bar"""

This looks like the string ends with three double quotes, but it's better
to think of it as one escaped double quote, which is written as "", and
then the double quote that ends the argument.

This should then produce the output that you want.

-- 
Russ Allbery (eagle@eyrie.org)             <https://www.eyrie.org/~eagle/>



reply via email to

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