[Rd] ASCII art in function documentation - difference html and text output?
Marc Schwartz
marc_schwartz at me.com
Thu Sep 5 17:36:49 CEST 2013
Rainer,
Have you tried:
\preformatted{...}
which is documented in R-exts to preserve line breaks:
Indicate text that is a literal example of a piece of a program. Text is displayed using typewriter font if possible. Formatting, e.g. line breaks, is preserved. (Note that this includes a line break after the initial {, so typically text should start on the same line as the command.)
Due to limitations in LaTeX as of this writing, this macro may not be nested within other markup macros other than \dQuote and \sQuote, as errors or bad formatting may result.
I have not used it myself, but might be worth a try, plus or minus the \cr use.
Regards,
Marc Schwartz
On Sep 5, 2013, at 10:23 AM, Rainer M Krug <Rainer at krugs.de> wrote:
> Found a solution.
>
> putting \cr at the end of each line inserts a carriage return, but no
> additional empty line. So
>
> ,----
> | \code{+------+------+------+} \cr
> | \code{| 1/16 | 1/16 | 1/16 |} \cr
> | \code{+------+------+------+} \cr
> | \code{| 1/16 | 8/16 | 1/16 |} \cr
> | \code{+------+------+------+} \cr
> | \code{| 1/16 | 1/16 | 1/16 |} \cr
> | \code{+------+------+------+} \cr
> `----
>
> produces the desired output.
>
>
> But interestingly,
>
> ,----
> | \code{
> | +------+------+------+ \cr
> | | 1/16 | 1/16 | 1/16 | \cr
> | +------+------+------+ \cr
> | | 1/16 | 8/16 | 1/16 | \cr
> | +------+------+------+ \cr
> | | 1/16 | 1/16 | 1/16 | \cr
> | +------+------+------+ \cr
> | }
> `----
>
> produces the correct output in html,
>
> ,----
> | </p>
> | <p><code> +------+------+------+ <br> | 1/16 | 1/16 | 1/16 |
> | <br> +------+------+------+ <br> | 1/16 | 8/16 | 1/16 | <br>
> | +------+------+------+ <br> | 1/16 | 1/16 | 1/16 | <br>
> | +------+------+------+ <br> </code>
> | </p>
> `----
>
> but
>
> ,----
> | ' +------+------+------+
> | | 1/16 | 1/16 | 1/16 |
> |
> | +------+------+------+
> | | 1/16 | 8/16 | 1/16 |
> | +------+------+------+
> | | 1/16 | 1/16 | 1/16 |
> | +------+------+------+
> `----
>
> in the text version - is there a bug somewhere?
>
> Thanks,
>
> Rainer
>
>
>
> Rainer M Krug <Rainer at krugs.de> writes:
>
>> Sarah Goslee <sarah.goslee at gmail.com> writes:
>>
>>> Untested, but did you try wrapping the whole thing in a single code block:
>>
>> Nope - also in one line.
>>
>> Rainer
>>
>>>
>>> \code{
>>> all
>>> the
>>> things
>>> }
>>>
>>> Sarah
>>>
>>> On Thu, Sep 5, 2013 at 10:10 AM, Rainer M Krug <Rainer at krugs.de> wrote:
>>>> Hi
>>>>
>>>> I want to include ascii art in a function documentation which should
>>>> look as follow:
>>>>
>>>> ,----
>>>> | +------+------+------+
>>>> | | 1/16 | 1/16 | 1/16 |
>>>> | +------+------+------+
>>>> | | 1/16 | 8/16 | 1/16 |
>>>> | +------+------+------+
>>>> | | 1/16 | 1/16 | 1/16 |
>>>> | +------+------+------+
>>>> `----
>>>>
>>>>
>>>> to keep the monospaced font even in html, I decided to use \code{}:
>>>>
>>>> ,----
>>>> | \code{+------+------+------+}
>>>> |
>>>> | \code{| 1/16 | 1/16 | 1/16 |}
>>>> |
>>>> | \code{+------+------+------+}
>>>> |
>>>> | \code{| 1/16 | 8/16 | 1/16 |}
>>>> |
>>>> | \code{+------+------+------+}
>>>> |
>>>> | \code{| 1/16 | 1/16 | 1/16 |}
>>>> |
>>>> | \code{+------+------+------+}
>>>> `----
>>>>
>>>> But the result was an empty line between each text:
>>>>
>>>> ,----
>>>> | '+------+------+------+'
>>>> |
>>>> | '| 1/16 | 1/16 | 1/16 |'
>>>> |
>>>> | '+------+------+------+'
>>>> |
>>>> | '| 1/16 | 8/16 | 1/16 |'
>>>> |
>>>> | '+------+------+------+'
>>>> |
>>>> | '| 1/16 | 1/16 | 1/16 |'
>>>> |
>>>> | '+------+------+------+'
>>>> `----
>>>>
>>>> and when no empty lines were included obviously put everything behind
>>>> each other.
>>>>
>>>> My question:
>>>>
>>>> Is there a way that I can achieve the ASCII art as shown above? Is there
>>>> a way of having a \linebreak which does not insert a new line?
>>>>
>>>> Thanks,
>>>>
>>>> Rainer
>>>>
>>>>
>>>> --
>> <#secure method=pgpmime mode=sign>
>>
> <#secure method=pgpmime mode=sign>
>
> --
> Rainer M. Krug
>
> email: RMKrug<at>gmail<dot>com
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel
mailing list