[racket] Scribble: Different output for LaTeX and HTML backends

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Dec 8 06:12:13 EST 2010

The element produced by exact will be displayed in both the HTML and
the PDF document.
The video embedding code should only be part of the HTML output, on the other
hand, the link to the video should only appear in the PDF document.
I need a way to know when not to produce an element.

I have written an html-only that only produces output for the PDF
document (see below),
but I can't figure out how to write pdf-only. In the HTML document the styles
only control the CSS styles, which means the meant-for-pdf text is still present
in the HTML file.

I have thought of some various non-pretty hacks:
  - use a CSS style pdf_only that displays as a single white pixel
  - use sed to remove the extraneous ouput after the initial generation
  - use an external text file to signal whether the output is for an
HTML or PDF document

An builtin parameter in Scribble that tells whether the output is HTML
or PDF would be
make life easier.

(define-runtime-path htmlonly.tex "htmlonly.tex")
(define-runtime-path htmlonly.css "htmlonly.css")

(define html-only-style
  (make-style "HTMLOnly"
              (list (make-css-addition htmlonly.css)
                    (make-tex-addition htmlonly.tex)

(define (html-only s . strs)
  (make-element html-only-style (cons s strs)))

The css and tex files are as follows:

$ cat ../math-scribble/htmlonly.css
.HTMLOnly {}

$ cat ../math-scribble/htmlonly.tex

/Jens Axel

2010/12/7 Matthias Felleisen <matthias at ccs.neu.edu>:
> Define a Scribble function like this:
> (define (exact . items)
>  (make-element (make-style "identity" '(exact-chars))
>                items))
> (provide exact)
> In your document, write
> @note{@exact{\raggedright Schelog (1993) \url{http://docs.racket-lang.org/racklog}}}
> -- Matthias

> On Dec 7, 2010, at 11:04 AM, Jens Axel Søgaard wrote:
>> In the HTML output, can I do more than just choose a new CSS style?
>> (If yes, can you point to the proper place in the manual?)
>> I know how to change the styles in the CSS file, but for the embedding code
>> below, I need to output HTML too.
>> Ideally, I'd like to write something a la:
>> @html/pdf{<scribble1>}{<scribble2>}
>> where <scribble1> and <scribble2> are place holders for standard
>> Scribble syntax.
>> E.g.
>> @html/pdf{ @italic{HTML}}{ @bold{PDF} }
>> would generate the word HTML in italic in the HTML output, and
>> the word PDF in bold the pdf document.
>> Given the html/pdf primitive, it would be straigthforward to generate
>> conditional outputs.
>> /Jens Axel
>> 2010/12/7 Robby Findler <robby at eecs.northwestern.edu>:
>>> You can just set up a new command and give it different
>>> implementations in a style.tex and for the HTML output. There is a
>>> section on this in the docs I believe.
>>> Robby
>>> On Tuesday, December 7, 2010, Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
>>>> Hi All,
>>>> I have a YouTube video, that I'd like to embed in the HTML output using the
>>>> following code:
>>>> <iframe title="YouTube video player" class="youtube-player"
>>>> type="text/html" width="480" height="390"
>>>> src="http://www.youtube.com/embed/J3WIPS3Uh_A?rel=0"
>>>> frameborder="0"></iframe>
>>>> In the PDF version, I'd like to use:
>>>> @hyperlink["Mathematical Proofs: The Cosine Rule <http://www.youtube.com/watch?v=J3WIPS3Uh_A>"]{Proof for the
>>>> cosine relation in an acute trinagle}
>>>> How can I detect whether pdf or html is being generated?
>>>> Is there a parameter I can use?
>>>> --
>>>> Jens Axel Søgaard
>>>> _________________________________________________
>>>>   For list-related administrative tasks:
>>>>   http://lists.racket-lang.org/listinfo/users
>>> _________________________________________________
>>>  For list-related administrative tasks:
>>>  http://lists.racket-lang.org/listinfo/users
>> --
>> --
>> Jens Axel Søgaard
>> _________________________________________________
>>  For list-related administrative tasks:
>>  http://lists.racket-lang.org/listinfo/users

Jens Axel Søgaard

Posted on the users mailing list.