observablehq / stdlib

The Observable standard library.
https://observablehq.com/@observablehq/standard-library
ISC License
966 stars 83 forks source link

TeX without double backslashes using String.raw? #10

Closed mbostock closed 6 years ago

mbostock commented 6 years ago

So, it looks like String.raw will let us write LaTeX without needing to double-escape backslashes:

texraw = {
  var raw = String.raw;
  function texraw() {
    return tex([raw.apply(String, arguments)]);
  }
  texraw.block = function() {
    return tex.block([raw.apply(String, arguments)]);
  };
  return texraw;
}
texraw`\Delta E^*_{00} = \sqrt{
  \Big(\frac{\Delta L'}{k_LS_L}\Big)^2 +
  \Big(\frac{\Delta C'}{k_CS_C}\Big)^2 +
  \Big(\frac{\Delta H'}{k_HS_H}\Big)^2 +
  R_T
  \frac{\Delta C'}{k_CS_C}
  \frac{\Delta H'}{k_HS_H}
}`

Do we want to change tex to do that automatically? Is there ever a reason you’d need to JavaScript string escapes within LaTeX?

mbostock commented 6 years ago

https://beta.observablehq.com/@mbostock/latex-without-double-backslashes

liuyao12 commented 6 years ago

I'd say make tex do that automatically (speaking as someone who doesn't do much JavaScript...)

BTW, the ability to make a piece of the expression reactive and changing is very exciting. Just need to find good use cases. My first try: https://beta.observablehq.com/@liuyao12/add-ad-infinitum