Re: [racket-users] Scribble: Typeset equations using Latex packages amsmath and amssym

2015-09-24 Thread Norman Gray


Greetings, all.

On 24 Sep 2015, at 13:12, Alex Knauth wrote:

Ah, I actually had tried that and was about to send you the error 
code for bad syntax. But then I realised that it complained about me 
defining $ as the equivalent of math-inline, which of course clashes 
with #\$.



Oh.
Well, if you can change the #\$ to a different character, say #\^, 
then you can use ^[\begin{equation*}] instead, to avoid clashes.


At the risk of a slight tangent...

Recall that (La)TeX allows fairly extensive reallocation of 
functionality to characters: the escape character doesn't have to be 
backslash, the math-open character doesn't have to be dollar.


In my experience, when generating (La)TeX, it's useful to do some 
category-code magic -- even using non-ASCII characters for some of the 
categories -- and generate LaTeX accordingly.  The resulting LaTeX looks 
weird, but completely avoids a whole class of escaping headaches.


Thus:

This is ^Aemph^Bemphasised^C text, and standard LaTeX.

I can fill in further details if that would be useful.

All the best,

Norman


--
Norman Gray  :  http://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Scribble: Typeset equations using Latex packages amsmath and amssym

2015-09-24 Thread Alex Knauth

> On Sep 24, 2015, at 7:51 AM, Marc Kaufmann  wrote:
> 
> Ah, I actually had tried that and was about to send you the error code for 
> bad syntax. But then I realised that it complained about me defining $ as the 
> equivalent of math-inline, which of course clashes with #\$.

Oh. 
Well, if you can change the #\$ to a different character, say #\^, then you can 
use ^[\begin{equation*}] instead, to avoid clashes.

> So now it works.
> 
> Btw, what does #\$ do? Is it a package? And does the order of the #lang 
> raw-string ... matter?

It's an option that allows you to change the character that it uses to start a 
raw string, and yes the order does matter.
You have to put the base language before the character, and since it takes a 
module language as a base, not a #lang language, you can't for instance do 
`#lang raw-string at-exp racket #\$`, but you can do `#lang at-exp raw-string 
racket #\$`, because at-exp is more flexible than raw-string.
It might be possible to make raw-string accept an arbitrary #lang language, but 
I don't know how.

> Thanks for the solutions,
> Marc
> 
> On Thu, Sep 24, 2015 at 7:34 AM, Alex Knauth  > wrote:
> 
>> On Sep 24, 2015, at 6:41 AM, Marc Kaufmann > > wrote:
>> 
>> Thanks Alex,
>> 
>> To avoid dealing with escapes like that, you could use the raw-string 
>> package, which lets you do this:
>> raco pkg install raw-string
>> 
>> #lang raw-string/raw-string racket/base #\$
>> 
>> 
>> When I add the package via raco and change the #lang line as you suggest, I 
>> get the following error when running scribble:
>> 
>> ---
>> marc$ scribble --prefix scribble-prefix.tex --pdf effort-tracking.scrbl 
>> standard-module-name-resolver: collection not found
>>   collection: "raw-string/raw-string/lang"
>>   in collection directories:
>>/home/marc/.racket/5.3.6/pkgs/installed/raw-string
>>/home/marc/.racket/5.3.6/pkgs/installed/base
>>/home/marc/.racket/5.3.6/collects
>>/usr/share/racket/collects
> 
> 
>> The raw-string package is actually under 
>> ~/.racket/5.3.6/pkgs/installed/raw-string, so I am not sure what's going on. 
> 
> It might have been installed as `#lang raw-string` then, does that work?
> 
> It might be an issue with older versions of racket interpreting it as a 
> multi-collection package instead of a single-collection package.
> 
> 
>> You could also use at-exp for that, but raw-string is simpler.
>> 
>> 
>> How does the at-exp work? Or do you mean at-exp with raw-string?
> 
> No, I mean at-exp by itself with racket/base:
> 
> #lang at-exp racket/base
> 
> (require scribble/base
>  scribble/core)
> 
> (provide equation*)
> 
> (define (mymath start end . strs)
>   (make-element (make-style "relax" '(exact-chars)) `(,start ,@strs ,end)))
> 
> (define (equation* . strs)
>   (apply mymath @~a|{\begin{equation*}}| @~a|{\end{equation*}}| strs))
> 
> 
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Scribble: Typeset equations using Latex packages amsmath and amssym

2015-09-24 Thread Marc Kaufmann
Thanks Alex,

To avoid dealing with escapes like that, you could use the raw-string
> package, which lets you do this:
> raco pkg install raw-string
>
> #lang raw-string/raw-string racket/base #\$
>
>
When I add the package via raco and change the #lang line as you suggest, I
get the following error when running scribble:

---
marc$ scribble --prefix scribble-prefix.tex --pdf effort-tracking.scrbl
standard-module-name-resolver: collection not found
  collection: "raw-string/raw-string/lang"
  in collection directories:
   /home/marc/.racket/5.3.6/pkgs/installed/raw-string
   /home/marc/.racket/5.3.6/pkgs/installed/base
   /home/marc/.racket/5.3.6/collects
   /usr/share/racket/collects
  context...:
   standard-module-name-resolver
   standard-module-name-resolver
   standard-module-name-resolver
   /usr/share/racket/collects/scribble/../racket/private/map.rkt:26:19: loop
   /usr/share/racket/collects/scribble/run.rkt: [running body]
---

The raw-string package is actually under
~/.racket/5.3.6/pkgs/installed/raw-string, so I am not sure what's going
on.


>
You could also use at-exp for that, but raw-string is simpler.
>
>
How does the at-exp work? Or do you mean at-exp with raw-string?

Thanks,

Marc

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Scribble: Typeset equations using Latex packages amsmath and amssym

2015-09-23 Thread Alexander D. Knauth

> On Sep 23, 2015, at 8:53 AM, Marc Kaufmann  wrote:

> #lang racket/base
> 
> (require scribble/base
> scribble/core)
> 
> (provide equation*)
> 
> (define (mymath start end . strs)
>  (make-element (make-style "relax" '(exact-chars)) `(,start ,@strs ,end)))
> 
> (define (equation* . strs)
>  (apply mymath "\\begin{equation*}" "\\end{equation*}" strs))
> 
> 
> 
> I still do not understand why I have to type "\\" rather than "\". I get that 
> something somewhere is escaping the backslash. I am uncomfortable with this, 
> as it seems that "{" and "}" are not escaped, but since I do not know what is 
> and what isn't, I may at some point in the future get a cryptic error message 
> because I used a command or a character in the strings that gets unescaped.

To avoid dealing with escapes like that, you could use the raw-string package, 
which lets you do this:
raco pkg install raw-string

#lang raw-string/raw-string racket/base #\$

(require scribble/base
 scribble/core)

(provide equation*)

(define (mymath start end . strs)
  (make-element (make-style "relax" '(exact-chars)) `(,start ,@strs ,end)))

(define (equation* . strs)
  (apply mymath $[\begin{equation*}] $[\end{equation*}] strs))

Those don't have to be [] brackets, they could be (), {}, <>, "", '', ^^, or 
any other pair of characters, as long as you don't try to put the ending 
character in the string.

You could also use at-exp for that, but raw-string is simpler.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Scribble: Typeset equations using Latex packages amsmath and amssym

2015-09-23 Thread Marc Kaufmann
Hi all,

I had a hard time to get any equations into my scribble document, as writing 

\begin{equation*} f(x) = x^2 \end{equation*}

would be turned into "$\backslash$begin...", which meant that it wouldn't 
actually show up as an equation but as garbage text with "begin{equation*}" and 
so on showing up. Since I found a way of getting it to work, I wanted to 
document it in baby steps that my 2-hours younger self would have understood 
faster than the links I found. Plus, I may be missing even easier solutions. 

The first problem with regards to equations in Latex is that Scribble 
(understandably) escapes some characters such as \ and $, so that Latex never 
sees the \begin, but $\backslash$. The second is to tell Scribble to load the 
Latex packages amsmath and amssymb. 

The solution to the first is to use Prabhakar Ragde's solution (see an example 
of it at https://gist.github.com/spdegabrielle/c9c9964d3e2fb4faa268). To get 
equation* working for instance, make a new file math.rkt (works for Latex only, 
for HTML see end of email, also from the above github link):



#lang racket/base

(require scribble/base
 scribble/core)

(provide equation*)

(define (mymath start end . strs)
  (make-element (make-style "relax" '(exact-chars)) `(,start ,@strs ,end)))

(define (equation* . strs)
  (apply mymath "\\begin{equation*}" "\\end{equation*}" strs))



I still do not understand why I have to type "\\" rather than "\". I get that 
something somewhere is escaping the backslash. I am uncomfortable with this, as 
it seems that "{" and "}" are not escaped, but since I do not know what is and 
what isn't, I may at some point in the future get a cryptic error message 
because I used a command or a character in the strings that gets unescaped.

Anway, once I do this, I can require math.rkt in my .scrbl file:



#lang scribble/base

@(require "math.rkt") ; Assumes math.rkt is in the same folder as .scrbl file

@title{Scribbling Equations}

@section{Equations at Work}

@equation*{f(x) = x^2}



To solve the second problem, make a new prefix file, math-prefix.tex:

---

\documentclass{article}

\usepackage[utf8]{inputenc} ; from standard prefix file
\usepackage[T1]{fontenc} ; from standard prefix file
\usepackage{amsmath} ; Required for equation*
\useapackage{amssymb} ; Required for a bunch of mathematical symbols

---

Finally, run the following on the command line:

scribble --prefix math-prefix.tex --pdf equations.scrbl

This worked for me. Is this the right way of loading extra packages? And when 
defining new mathematical commands in this way, what characters that might get 
escaped do I have to worry about? 

As for getting it to work with HTML, one should add the following to the 
math.rkt file:

--- 

#lang racket/base
; From http://con.racket-lang.org/pr-slides.pdf
; by Prabhakar Ragde
(require scribble/html-properties ; THIS IS NEW
 scribble/base
 scribble/core)

(provide ...)

; ADD THIS: It defines the link to MathJax, a library which turns Latex math 
; into proper form on websites
(define mathjax-source
  
"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"; 
  )

; By using @setup-math in your .scrbl file, this loads the mathjax library
(define setup-math
  (paragraph 
   (style 
#f (list (alt-tag "script")
 (attributes `((type . "text/javascript")
   (src . ,mathjax-source )
   '()))

---

Thanks for reading this far. And just to be clear, I am not taking credit for 
this solution, but I found the existing links to be unclear, and only 
addressing one part of the problem, which meant that I wasn't even sure what 
went wrong when it did. Hope this helps someone.

Cheers,
Marc

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.