questions on MathJax #25

Open
opened 5 years ago by jtangpanitanon · 11 comments
jtangpanitanon commented 5 years ago (Migrated from github.com)

Hi, I'm a new pollen & racket users. I am experimenting with the source code for "Typography for Laywers" and trying to add LaTex equations into it on my computer.

Here is what I added into my html.pp file

◊(define ($ . xs) (mathjax ,(apply string-append ("$" ,@xs "$")))) ◊(define ($$ . xs) (mathjax ,(apply string-append `("" ,@xs ""))))

◊(define-meta title "where do the rules come from?")
◊hanging-topic[(topic-from-metas metas)]{Professional typography}

Example 1: ◊h1{◊${\mathcal{O} = 2_{\alpha+1}}}
Example 2: ◊${|\psi\rangle = \sum_nc_n|n\rangle}
`

However, the latex code only appears correctly in Example 1 where '◊h1' is used but this creates a bigger font than what I need. How can I make the latex code works without '◊h1'?

Another question is how do I move the following lines to pollen.rkt file? This is not obvious to me in the tutorial.

◊(define ($ . xs) (mathjax ,(apply string-append ("$" ,@xs "$")))) ◊(define ($$ . xs) (mathjax ,(apply string-append `("" ,@xs ""))))

Thanks!

Hi, I'm a new pollen & racket users. I am experimenting with [the source code](https://github.com/mbutterick/pollen-tfl) for "Typography for Laywers" and trying to add LaTex equations into it on my computer. Here is what I added into my html.pp file > `◊(define ($ . xs) > `(mathjax ,(apply string-append `("$" ,@xs "$")))) > ◊(define ($$ . xs) > `(mathjax ,(apply string-append `("$$" ,@xs "$$")))) > > ◊(define-meta title "where do the rules come from?") > ◊hanging-topic[(topic-from-metas metas)]{Professional typography} > > Example 1: ◊h1{◊${\mathcal{O} = 2_{\alpha+1}}} > Example 2: ◊${|\psi\rangle = \sum_nc_n|n\rangle} > ` However, the latex code only appears correctly in Example 1 where '◊h1' is used but this creates a bigger font than what I need. How can I make the latex code works without '◊h1'? Another question is how do I move the following lines to pollen.rkt file? This is not obvious to me in the tutorial. > `◊(define ($ . xs) > `(mathjax ,(apply string-append `("$" ,@xs "$")))) > ◊(define ($$ . xs) > `(mathjax ,(apply string-append `("$$" ,@xs "$$")))) > Thanks!
sorawee commented 5 years ago (Migrated from github.com)

Welcome to Pollen and Racket!

FYI, in Github issues, which use Markdown, you should use triple backtick when you want to show a fragment of code so that the code is displayed verbatim and not parsed as Markdown.

For your second question, put:

(define ($ . xs)
  `(mathjax ,(apply string-append `("$" ,@xs "$"))))
(define ($$ . xs)
  `(mathjax ,(apply string-append `("$$" ,@xs "$$"))))

in pollen.rkt. Make sure that your pollen.rkt either has (provide (all-defined-out)) or (provide $ $$) (you probably want the former).

What happens to Example 2? Can you show me the output?

Welcome to Pollen and Racket! FYI, in Github issues, which use Markdown, you should use triple backtick when you want to show a fragment of code so that the code is displayed verbatim and not parsed as Markdown. For your second question, put: ``` (define ($ . xs) `(mathjax ,(apply string-append `("$" ,@xs "$")))) (define ($$ . xs) `(mathjax ,(apply string-append `("$$" ,@xs "$$")))) ``` in `pollen.rkt`. Make sure that your `pollen.rkt` either has `(provide (all-defined-out))` or `(provide $ $$)` (you probably want the former). What happens to Example 2? Can you show me the output?
sorawee commented 5 years ago (Migrated from github.com)

This is a minimal example of what you are trying to do. It seems to work fine for me.

Screen Shot 2019-12-31 at 19 40 14

Note that I have three files in the project directory: pollen.rkt, template.html.p, and test.html.pm. In Pollen, the file extension is important. Not sure if the problem that you experienced is related to the fact that you name your file html.pp.

This is a minimal example of what you are trying to do. It seems to work fine for me. <img width="1280" alt="Screen Shot 2019-12-31 at 19 40 14" src="https://user-images.githubusercontent.com/9099577/71637903-62aa2d80-2c05-11ea-93c4-4adaa8dd8457.png"> Note that I have three files in the project directory: `pollen.rkt`, `template.html.p`, and `test.html.pm`. In Pollen, the file extension is important. Not sure if the problem that you experienced is related to the fact that you name your file `html.pp`.
jtangpanitanon commented 5 years ago (Migrated from github.com)

Hi @sorawee , thanks for your nice answer. I tried to copy your solution, it kind of works but is slightly different than yours. Any ideas what went wrong?

Screen Shot 2020-01-09 at 2 32 28 PM

<test.html.pm>

#lang pollen
  
◊(define-meta title "Hello World!")

Example 1: ◊h1{◊${\mathcal{O} = 2_{\alpha+1}}}
Example 2: ◊${|\psi\rangle = \sum_nc_n|n\rangle}

<pollen.rkt>

#lang racket
  
(provide (all-defined-out))

(define ($ . xs)
  `(mathjax ,(apply string-append `("$" ,@xs "$"))))
(define ($$ . xs)
  `(mathjax ,(apply string-append `("$$" ,@xs "$$"))))

<template.html.p>

<!DOCTYPE html>
  
<html>
  <head>
    <script type="text/javascript"
      src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>

     <script type="text/x-mathjax-config">
        MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']]}});
     </script>
     <title>◊(select-form-metas 'title here)</title>
  </head>
  <body>
    <h1>◊(select-from-metas 'title here)</h1>
    ◊(->html doc)
  </body>
</html>
Hi @sorawee , thanks for your nice answer. I tried to copy your solution, it kind of works but is slightly different than yours. Any ideas what went wrong? <img width="570" alt="Screen Shot 2020-01-09 at 2 32 28 PM" src="https://user-images.githubusercontent.com/53329837/72043821-2a81a980-32ed-11ea-9f4b-474d4340df34.png"> <test.html.pm> ``` #lang pollen ◊(define-meta title "Hello World!") Example 1: ◊h1{◊${\mathcal{O} = 2_{\alpha+1}}} Example 2: ◊${|\psi\rangle = \sum_nc_n|n\rangle} ``` <pollen.rkt> ``` #lang racket (provide (all-defined-out)) (define ($ . xs) `(mathjax ,(apply string-append `("$" ,@xs "$")))) (define ($$ . xs) `(mathjax ,(apply string-append `("$$" ,@xs "$$")))) ``` <template.html.p> ``` <!DOCTYPE html> <html> <head> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']]}}); </script> <title>◊(select-form-metas 'title here)</title> </head> <body> <h1>◊(select-from-metas 'title here)</h1> ◊(->html doc) </body> </html> ```
jtangpanitanon commented 5 years ago (Migrated from github.com)

Also, another problem is when I try to add your suggestion in <pollen.rkt> in the template for "Typography for Laywers"

#lang pollen/mode racket/base
(require "scribblings/pollen-rkt.scrbl" pollen/tag)
(provide (all-from-out "scribblings/pollen-rkt.scrbl"))

(module setup racket/base
  (provide (all-defined-out)) ;; <- don't forget this line in your config submodule!
  (require pollen/setup racket/path)
  (define (omitted-path? p) (path-has-extension? p #".sh")))

(provide ie-payment-warning)
(define (ie-payment-warning)
  (define div (default-tag-function 'div))
  (define p (default-tag-function 'p))
  (define strong (default-tag-function 'strong))
  ◊div[#:class "ie reader-note"]{◊p{Because of security considerations, my payment links ◊strong{do not support Internet Explorer 11 or earlier}. Please use a different browser.}})

(define ($ . xs)
`(mathjax ,(apply string-append `("$" ,@xs "$"))))
(define ($$ . xs)
`(mathjax ,(apply string-append `("$$" ,@xs "$$"))))

with the following html.pm file

#lang pollen
  
◊(define-meta title "where do the rules come from?")
◊hanging-topic[(topic-from-metas metas)]{Professional typography}

Example 1: ◊h1{◊${\mathcal{O} = 2_{\alpha+1}}}
Example 2: ◊${|\psi\rangle = \sum_nc_n|n\rangle}

I get the following

Screen Shot 2020-01-09 at 3 13 41 PM
Also, another problem is when I try to add your suggestion in <pollen.rkt> in the template for ["Typography for Laywers"](https://github.com/mbutterick/pollen-tfl) ``` #lang pollen/mode racket/base (require "scribblings/pollen-rkt.scrbl" pollen/tag) (provide (all-from-out "scribblings/pollen-rkt.scrbl")) (module setup racket/base (provide (all-defined-out)) ;; <- don't forget this line in your config submodule! (require pollen/setup racket/path) (define (omitted-path? p) (path-has-extension? p #".sh"))) (provide ie-payment-warning) (define (ie-payment-warning) (define div (default-tag-function 'div)) (define p (default-tag-function 'p)) (define strong (default-tag-function 'strong)) ◊div[#:class "ie reader-note"]{◊p{Because of security considerations, my payment links ◊strong{do not support Internet Explorer 11 or earlier}. Please use a different browser.}}) (define ($ . xs) `(mathjax ,(apply string-append `("$" ,@xs "$")))) (define ($$ . xs) `(mathjax ,(apply string-append `("$$" ,@xs "$$")))) ``` with the following html.pm file ``` #lang pollen ◊(define-meta title "where do the rules come from?") ◊hanging-topic[(topic-from-metas metas)]{Professional typography} Example 1: ◊h1{◊${\mathcal{O} = 2_{\alpha+1}}} Example 2: ◊${|\psi\rangle = \sum_nc_n|n\rangle} ``` I get the following <img width="746" alt="Screen Shot 2020-01-09 at 3 13 41 PM" src="https://user-images.githubusercontent.com/53329837/72046220-e72a3980-32f2-11ea-9cb0-99f95e5f8794.png">
sorawee commented 5 years ago (Migrated from github.com)

Let me address your first comment first. That is not a Pollen issue. Different browser has different initial CSS style settings. I used Chrome when I took the screenshot above. If you use a different browser (e.g., Safari), that would explain the discrepancy.

FWIW, there are several CSS libraries that attempt to give a better default settings so that all browsers have the same appearance. For example:

So I recommend loading one of these in template.html.p (in the <head> section) to make browsers appear in the same way.

Let me address your first comment first. That is not a Pollen issue. Different browser has different initial CSS style settings. I used Chrome when I took the screenshot above. If you use a different browser (e.g., Safari), that would explain the discrepancy. FWIW, there are several CSS libraries that attempt to give a better default settings so that all browsers have the same appearance. For example: - [Reboot](https://getbootstrap.com/docs/4.4/content/reboot/) (as a part of the Bootstrap framework) - [Normalize.css](https://necolas.github.io/normalize.css/) So I recommend loading one of these in `template.html.p` (in the `<head>` section) to make browsers appear in the same way.
sorawee commented 5 years ago (Migrated from github.com)

For your second comment: did you add

<script type="text/javascript"
        src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']]}});
</script>

to your template.html.p?

For your second comment: did you add ``` <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']]}}); </script> ``` to your `template.html.p`?
jtangpanitanon commented 5 years ago (Migrated from github.com)

For your second comment: did you add

<script type="text/javascript"
        src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']]}});
</script>

to your template.html.p?

Yep this is my template.html.p

<!DOCTYPE html>
◊(define parent-page (parent here))
◊(define previous-page (previous here))
◊(define next-page (next here))
◊(define here-title (or (select-from-metas 'title here) (symbol->string here)))
◊(define toolbar? (not (select-from-metas 'toolbar-blank metas)))

◊(define (make-side-nav id url text)
  ◊div[#:class "nav-outer" #:id id]{◊(link (or url "") ◊div[#:class "nav-inner"]{◊div[#:class "nav-flex" text]})})
◊(define center-cell-width 14)
◊(define side-cell-width (/ (- 100 (+ 10 (* center-cell-width 2))) 2))
◊(local-require pollen/tag)
◊; the name `link` is already defined as a function that makes hyperlinks,
◊; so we use `make-default-tag-function` to make a literal `link` tag
◊(define literal-link (make-default-tag-function 'link)) 
◊(define (make-subnav children)
  (apply ul #:class "subnav"
    (for/list ([child (in-list children)])
      (li (xref (select-from-metas 'title child))))))

◊(local-require css-tools)

<head>
<script type="text/javascript"
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']]}});
</script>
<title>◊(select-form-metas 'title here)</title>

  <meta charset="UTF-8">
    <script type="text/javascript">
if (navigator.appVersion.indexOf("Win")!=-1) {
    ◊; got windows
    document.write('<link rel="stylesheet" type="text/css" media="all" href="fonts/equity-a.css" />');
} else if (navigator.appVersion.indexOf("Mac")!=-1) {
    if (navigator.userAgent.match(/iPad/i) != null) {
        ◊; got ipad
        ◊; style sheet for ipad 2
        document.write('<link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="fonts/equity-b.css" type="text/css" />');
        ◊; style sheet for ipad 3
        document.write('<link rel="stylesheet" media="only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (-webkit-min-device-pixel-ratio: 2)" type="text/css" href="fonts/equity-a.css" />');
    } else {
        ◊; got mac
        document.write('<link rel="stylesheet" type="text/css" media="all" href="fonts/equity-b.css" />');
    }
} else {
    ◊; got something else
    document.write('<link rel="stylesheet" type="text/css" media="all" href="fonts/equity-a.css" />');
}

</script>

... 
> For your second comment: did you add > > ``` > <script type="text/javascript" > src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> > </script> > > <script type="text/x-mathjax-config"> > MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']]}}); > </script> > ``` > > to your `template.html.p`? Yep this is my template.html.p ``` <!DOCTYPE html> ◊(define parent-page (parent here)) ◊(define previous-page (previous here)) ◊(define next-page (next here)) ◊(define here-title (or (select-from-metas 'title here) (symbol->string here))) ◊(define toolbar? (not (select-from-metas 'toolbar-blank metas))) ◊(define (make-side-nav id url text) ◊div[#:class "nav-outer" #:id id]{◊(link (or url "") ◊div[#:class "nav-inner"]{◊div[#:class "nav-flex" text]})}) ◊(define center-cell-width 14) ◊(define side-cell-width (/ (- 100 (+ 10 (* center-cell-width 2))) 2)) ◊(local-require pollen/tag) ◊; the name `link` is already defined as a function that makes hyperlinks, ◊; so we use `make-default-tag-function` to make a literal `link` tag ◊(define literal-link (make-default-tag-function 'link)) ◊(define (make-subnav children) (apply ul #:class "subnav" (for/list ([child (in-list children)]) (li (xref (select-from-metas 'title child)))))) ◊(local-require css-tools) <head> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']]}}); </script> <title>◊(select-form-metas 'title here)</title> <meta charset="UTF-8"> <script type="text/javascript"> if (navigator.appVersion.indexOf("Win")!=-1) { ◊; got windows document.write('<link rel="stylesheet" type="text/css" media="all" href="fonts/equity-a.css" />'); } else if (navigator.appVersion.indexOf("Mac")!=-1) { if (navigator.userAgent.match(/iPad/i) != null) { ◊; got ipad ◊; style sheet for ipad 2 document.write('<link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="fonts/equity-b.css" type="text/css" />'); ◊; style sheet for ipad 3 document.write('<link rel="stylesheet" media="only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (-webkit-min-device-pixel-ratio: 2)" type="text/css" href="fonts/equity-a.css" />'); } else { ◊; got mac document.write('<link rel="stylesheet" type="text/css" media="all" href="fonts/equity-b.css" />'); } } else { ◊; got something else document.write('<link rel="stylesheet" type="text/css" media="all" href="fonts/equity-a.css" />'); } </script> ... ```
sorawee commented 5 years ago (Migrated from github.com)

I believe the issue is that you didn't (provide (all-defined-out)) in pollen.rkt. If you don't want to provide everything that you define in that file, you can also just (provide $ $$) to selectively provide the two tags that you created.

I believe the issue is that you didn't `(provide (all-defined-out))` in `pollen.rkt`. If you don't want to provide everything that you define in that file, you can also just `(provide $ $$)` to selectively provide the two tags that you created.
jtangpanitanon commented 5 years ago (Migrated from github.com)

I believe the issue is that you didn't (provide (all-defined-out)) in pollen.rkt. If you don't want to provide everything that you define in that file, you can also just (provide $ $$) to selectively provide the two tags that you created.

Thanks @sorawee . It seems to solve half of the problem :)

Screen Shot 2020-01-09 at 4 08 47 PM

#lang pollen/mode racket/base
  
(provide (all-defined-out))

(require "scribblings/pollen-rkt.scrbl" pollen/tag)
(provide (all-from-out "scribblings/pollen-rkt.scrbl"))

(module setup racket/base
  (provide (all-defined-out)) ;; <- don't forget this line in your config submodule!
  (require pollen/setup racket/path)
  (define (omitted-path? p) (path-has-extension? p #".sh")))

(provide ie-payment-warning)
(define (ie-payment-warning)
  (define div (default-tag-function 'div))
  (define p (default-tag-function 'p))
  (define strong (default-tag-function 'strong))
  ◊div[#:class "ie reader-note"]{◊p{Because of security considerations, my payment links ◊strong{do not support Internet Explorer 11 or earlier}. Please use a different browser.}})

(define ($ . xs)
`(mathjax ,(apply string-append `("$" ,@xs "$"))))
(define ($$ . xs)
`(mathjax ,(apply string-append `("$$" ,@xs "$$"))))
> I believe the issue is that you didn't `(provide (all-defined-out))` in `pollen.rkt`. If you don't want to provide everything that you define in that file, you can also just `(provide $ $$)` to selectively provide the two tags that you created. Thanks @sorawee . It seems to solve half of the problem :) ![Screen Shot 2020-01-09 at 4 08 47 PM](https://user-images.githubusercontent.com/53329837/72049691-6c651c80-32fa-11ea-8951-26e6a6a045e4.png) ``` #lang pollen/mode racket/base (provide (all-defined-out)) (require "scribblings/pollen-rkt.scrbl" pollen/tag) (provide (all-from-out "scribblings/pollen-rkt.scrbl")) (module setup racket/base (provide (all-defined-out)) ;; <- don't forget this line in your config submodule! (require pollen/setup racket/path) (define (omitted-path? p) (path-has-extension? p #".sh"))) (provide ie-payment-warning) (define (ie-payment-warning) (define div (default-tag-function 'div)) (define p (default-tag-function 'p)) (define strong (default-tag-function 'strong)) ◊div[#:class "ie reader-note"]{◊p{Because of security considerations, my payment links ◊strong{do not support Internet Explorer 11 or earlier}. Please use a different browser.}}) (define ($ . xs) `(mathjax ,(apply string-append `("$" ,@xs "$")))) (define ($$ . xs) `(mathjax ,(apply string-append `("$$" ,@xs "$$")))) ```
sorawee commented 5 years ago (Migrated from github.com)

The problem is that Typography for Lawyers (henceforth TfL) has a lot of black magic that you really don't want. In this case, the problem is caused by the automatic hyphenation, which attempts to hyphenate your LaTeX code because it doesn't know that your code is not a prose that should not be tampered with. One way to fix the problem is to add mathjax to the list of tags on this line in pollen-rkt.scrbl to make the automatic hyphenation skips LaTeX code.

But again, you really don't want to base your project on TfL. TfL is in fact a quite unconventional Pollen project, e.g., using literate programming instead of writing code as usual. You probably won't need any of these features.

The problem is that Typography for Lawyers (henceforth TfL) has a lot of black magic that you really don't want. In this case, the problem is caused by the automatic hyphenation, which attempts to hyphenate your LaTeX code because it doesn't know that your code is not a prose that should not be tampered with. One way to fix the problem is to add `mathjax` to the list of tags on [this line](https://github.com/mbutterick/pollen-tfl/blob/master/scribblings/pollen-rkt.scrbl#L820) in `pollen-rkt.scrbl` to make the automatic hyphenation skips LaTeX code. But again, you really don't want to base your project on TfL. TfL is in fact a quite unconventional Pollen project, e.g., using [literate programming](https://en.wikipedia.org/wiki/Literate_programming) instead of writing code as usual. You probably won't need any of these features.
jtangpanitanon commented 5 years ago (Migrated from github.com)

Wow it works like magic. Thanks @sorawee ! I just found TfL template is quite beautiful and as I don't have HTML background, I won't be able to design things from scratch.

Wow it works like magic. Thanks @sorawee ! I just found TfL template is quite beautiful and as I don't have HTML background, I won't be able to design things from scratch.
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/pollen-users#25
Loading…
There is no content yet.