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

50 views
Skip to first unread message

Jens Axel Søgaard

unread,
Dec 7, 2010, 10:27:42 AM12/7/10
to racket
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["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

Robby Findler

unread,
Dec 7, 2010, 10:40:57 AM12/7/10
to Jens Axel Søgaard, racket
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 <jens...@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

Jens Axel Søgaard

unread,
Dec 7, 2010, 11:04:55 AM12/7/10
to Robby Findler, racket
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 <ro...@eecs.northwestern.edu>:

--

Matthias Felleisen

unread,
Dec 7, 2010, 11:30:46 AM12/7/10
to Jens Axel Søgaard, racket, Robby Findler

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

Sam Tobin-Hochstadt

unread,
Dec 7, 2010, 11:39:34 AM12/7/10
to Matthias Felleisen, Jens Axel Søgaard, Robby Findler, racket
On Tue, Dec 7, 2010 at 11:30 AM, Matthias Felleisen
<matt...@ccs.neu.edu> wrote:
>
> Define a Scribble function like this:
>
> (define (exact . items)
>  (make-element (make-style "identity" '(exact-chars))
>                items))
> (provide exact)

This relies on a Latex macro named \identity being defined earlier in
the document. We might want to add this to the scribble prefix.

Probably there should be an alternate version for HTML (and for other backends).
--
sam th
sa...@ccs.neu.edu

Jens Axel Søgaard

unread,
Dec 8, 2010, 6:12:13 AM12/8/10
to Matthias Felleisen, racket
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)
'exact-chars)))

(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
\newcommand{\HTMLOnly}[1]{}

/Jens Axel

2010/12/7 Matthias Felleisen <matt...@ccs.neu.edu>:

Jens Axel Søgaard

unread,
Dec 8, 2010, 8:06:45 AM12/8/10
to racket
2010/12/7 Matthias Felleisen <matt...@ccs.neu.edu>:

> Define a Scribble function like this:
>
> (define (exact . items)
>  (make-element (make-style "identity" '(exact-chars))
>                items))
> (provide exact)

It (finally) dawned on me that I have two problems.
I thougt this would display a YouTube player on the HTML page:

@exact|{<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>}|

But since the element passes through the renderer, I get the above
string displayed as is on the HTML page.
Is there a loop hole that allows one to pass HTML untouched through
the renderer?

/Jens Axel

Matthew Flatt

unread,
Apr 4, 2011, 4:34:46 PM4/4/11
to Jens Axel Søgaard, racket
Maybe too late for your purposes, but...

At Tue, 7 Dec 2010 16:27:42 +0100, Jens Axel Søgaard wrote:
> 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["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?

I've finally added support for conditional content through a new
`scriblib/render-cond' library (which builds on a small core addition
to `traverse-element' and `traverse-block' plus).

Here's an example:

#lang scribble/base
@(require scriblib/render-cond
scribble/core)

@(cond-element
[latex (make-element "LaTeX" "")]
[html "HTML"]
[text "Text"])
is the best document format ever!


At Wed, 8 Dec 2010 14:06:45 +0100, Jens Axel Søgaard wrote:
> It (finally) dawned on me that I have two problems.
> I thougt this would display a YouTube player on the HTML page:
>
> @exact|{<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>}|
>
> But since the element passes through the renderer, I get the above
> string displayed as is on the HTML page.
> Is there a loop hole that allows one to pass HTML untouched through
> the renderer?

I'm reluctant to make 'exact affect HTML output or to otherwise resort
to literal string inclusion. The `attributes' structure from
`scribble/html-attributes' lets you add arbitrary attributes to HTML
output, and I've added an `alt-tag' structure to pick a tag such as
<iframe>:

#lang scribble/base
@(require scribble/core
scribble/html-properties)

@(make-element
(make-style #f
(list
(make-alt-tag "iframe")
(make-attributes
`((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")))))
null)

Reply all
Reply to author
Forward
0 new messages