Open rusimody opened 2 years ago
Hey @rusimody, I'm glad you like it π
Admittedly, I thought o-thread-blockcall
was a neat idea and so implemented it; but I, apparently , never actually use it for anything (i.e., for any blocks I've actually defined). It seems that it's broken; i.e., has not been maintained as other things have been improved. A nice thing to do, after fixing it, would be to add unit tests. π£
But the idea of o-thread-blockcall
is pretty straightforward, it's a mixture of thread-last
and o--blockcall
, so we can
just use these two togehter to achieve your aim. π
(o-defblock align nil nil
"A block for aligned equations."
(format "\\begin{align*} %s \\end{align*}" raw-contents))
(o-defblock goftex (shorthands "-> to \\Rightarrow") nil
"SHORTHANDS is a comma-separated list of βtoβ-separated string-to-LaTeX pairs."
(thread-last raw-contents ;; Get the block's raw contents,
(o--blockcall align) ;; Place them in an βalignβ block,
(o--blockcall rename shorthands) ;; Place that into a βrenameβ block
(s-replace-regexp "#\\+.*" ""))) ;; (β implementation fudge factor)
Since the above (o-defblock align ...)
is pretty barebones, here's a fancy one for you ---on the house π
(o-defblock align nil (numbered nil)
"A block for aligned equations.
- NUMBERED: Non-nil if you want the equations to be numbered.
- Lines that have a β\\tagβ, a display name, override any numbering.
- Block contents are interpretted directly as LaTeX elements, not Org markup.
- The ampersand character & determines where the equations align.
- We provide a shorthand for beautifully coloured tags, and labels:
- β :tag-πͺπΆπ³πΆπΌπΉ: π»π°π»π³π¬ β β β \\tag{$\\color{πͺπΆπ³πΆπΌπΉ}{π»π°π»π³π¬}$} \\label{π»π°π»π³π¬} \\\\ β
- Note, if a line does not have such a tag, it should end with β\\\\β.
- Finally, for MathJax to be loaded via Org, you should have some Math outside
this block; e.g., $\\;$ anywhere in your Org document, or an \\eqref{β―} anywhere.
Example use:
#+begin_align
y &= m \\cdot x + b & e^{i \\cdot \\pi} + 1 = 0 :tag-pink: Weird Symbols
rise &= slope \\cdot run + base & \\mathsf{fun\\; circle\\; stuff} :tag-blue: Friendly English
\\hline
p β§ q &β‘ p β‘ q β‘ p β¨ q & \\min\\{p, q\\} = p \\;β‘\\; q = \\max\\{p,q\\} :tag-gold: Golden Rule
#+end_align
Since πΉoolean equivalence, ββ‘β, is associative and symmetric; the \eqref{Golden Rule}
can be parsed as a definition for (1) conjunction ββ§β, (2) equivalence ββ‘β, and (3) disjunction ββ¨β."
(-let [n? (if numbered "" "*")]
(format "\\begin{align%s}\n %s \n\\end{align%s}" n?
(s-replace-regexp ":tag-\\(.*\\):\\( \\)*\\(.*\\)\\( \\)*"
"\\\\tag{$\\\\color{\\1}{\\\\text{\\3}}$} \\\\label{\\3} \\\\\\\\"
raw-contents)
n?)))
With this new fancy definition loaded, you can type into an Org file...
(Note: $\\Rightarrow$ is implication.)
#+begin_goftex "== to \\quad\\equiv\\quad, -> to \\Rightarrow, TT to \\mathsf{true}"
p -> p &== TT :tag-green: $->$-reflexivity
TT &== p -> p :tag-blue: $TT$-definition
#+end_goftex
Then when you export (to HTML), you obtain...
OOOOO---FFFF!! Thanks for taking so much trouble. And that's some heavy duty macrology out there... It'll take me a bit to digest ππ
Currently I am grappling with some more basic stuff
I am getting some spurious stuff in the contents
string
Your blocks seem not to suffer it while mine (current attempts) do
Here's a hopefully small eg Took your stutter
renamed mystutter
and added a print
. Thus:
(o-defblock mystutter (reps 2) nil
"Output the CONTENTS of the block REPS many times"
(-let [num (if (numberp reps) reps (string-to-number reps))]
(print (format "contents: %s" contents))
(s-repeat num contents)
))
With that stutter seems to work ok But my messages buffer shows:
"contents:
#+end_export
The actual content of my blocks call
#+begin_export latex
"
Notice the "#+end..."
... "#begin..."
???
Somehow your example blocks don't suffer this extra while mine do I can of course strip this stuff off. But I dont know what exactly it is and if its details can be different. So would like some clarity on that.
Also here's my current attempt of what I am trying to do. (My latex is weaker than my Lisp; And html side not worked out at all for now
(o-defblock double nil nil
"Makes a minipage pair of haskell and python which is SSS separated"
(let* ((hp (s-split "SSS" contents))
(h (car hp))
(p (cadr hp))
;;(h' (blockcall rename rlist h))
(hmp (format (pcase backend
(`latex
;; the {3in} was {\\linewidth}
"\\par
\\begin{minipage}[t]{3in}
\\begin{multicols}{%s}
%s
\\end{multicols}\\end{minipage}")
(_
"<div style=\"column-count: %s;\">%s</div>"))
2 h))
(pmp (format (pcase backend
(`latex
"\\par
\\begin{minipage}[t]{3in}
\\begin{multicols}{%s}
%s
\\end{multicols}\\end{minipage}")
(_
"<div style=\"column-count: %s;\">%s</div>"))
2 p)))
(print (format "contents: %s" contents))
(format "%s %s" hmp pmp))
)
Being a teacher myself I'd say this is D-grade Lisp so far π
a. I just took your parallel block and started hacking on it
b. The 3in
is because I am still figuring out what goes there
c. The html is completely unworked out; just copy of yours with the "%s"es removed to match the actual formats
d. hp
is the incoming haskell-python pair, h
is haskell part p
is python part hmp
is haskell-minipage Likewise pmp
e. The h' is for the yet to be done rename
that I earlier talked of
Actually I want the haskell to be in begin{align}
etc ie as math
And the python to be in #+begin_src python
... But this part is not anywhere there yet since I am not getting much more basic stuff like passing parameters etc yet
Aaahhh Just noticed your...
(s-replace-regexp "#\\+.*" ""))) ;; (β implementation fudge factor)
ππ
When and how to use??
Here's a mwe of what I want to do:
#+begin_double
id.x = x
SSS
def id(x): return x
#+end_double
A nice thing to do, after fixing it, would be to add unit tests.
I did notice some typos, doc bugs etc. If you like I could send a pull request for these (the ones I immediately see)
Thanks for some mind-blowing elisp work!
Just trying to figure out how to use
o-thread-blockcall
Basically I want to use
#begin_rename
with a fixed list And then wrap it in#begin_eqnarray*
Currently I hacked this far Which basically cutpasted your
rename
block and hardcoded (one element of) the list I want replaced.goftex
is the block I want -- gofer as Latex equationsObviously I'd prefer to reuse your
rename
not cutpaste it! The other thing is that in the current attempt, org is not recognizing#begin_eqnarray
if it is mixed with mygoftex
. Result of that is that I get extra\(
and\)
enclosing the\leftarrow
inside thebegin{eqnarray*}