Replace &nl; with \\newline in tex

Jan 21, 2016 at 5:14 PM
I've a custom block hsitory :
~ history {name:"aaa"}
line1
line2
~
Which I'd like to be translated in latex :
\history{aaa}{line1\newline{}line 2}
The rule
history {  tex-cmd: "\history{&name;}" }
gives me the \history command, but how can I replace &nl; with \\nweline ?

I tried with replace, but \ are escaped in the resulting tex source.

Thank you for your help, madoko is really nice !
Coordinator
Jan 21, 2016 at 5:42 PM
Thanks for enjoying Madoko :-)

Generally, you should not do a replace and put in LaTeX commands -- replace takes Madoko to Madoko code. One way to do this is to insert &br; line break characters that get translated to LaTeX line breaks:
history {
  tex-cmd:"\history{&name;}";
  replace:"/\n/&br;/g";
}
This will look good in the HTML output too. Actually, I don't know how you plan to render this but perhaps you should not even use a latex history command but render it directly in Madoko (so HTML looks good too). For example:
history {
  before: "** history &name;**:&nl;";
  padding: 1em;
  text-indent: -1em;
  replace:"/\n/&br;/g";
}
I hope this helps. Ah, if you really need \newline as you originally asked, perhaps it works best to first replace newline characters by an empty span []{.newline} and then put in a tex-cmd attribute on those spans. For example:
history {
  tex-cmd:"\history{&name;}";
  replace:"/\n/[]{.newline}/g";
}
.newline {
  tex-cmd:"\newline";
}
Marked as answer by matclab on 1/22/2016 at 12:28 AM
Jan 22, 2016 at 7:28 AM
Thank you very much.

The two step replacement works as expected… (I needed to keep the \history command, which is mandatory in our corporate LateX class).

It looks like Madoko will gain some usage here :-)