2

I am using polymode to edit rmarkdown files. Exporting to e.g. pdf is super simple and works very well. R code chunks are also properly highlighted.

But:

I do quite often use latex code inside (r)markdown. Would it be possible to highlight the latex code as well?

I guessed I need something like latex as a second major mode or a markdown-latex-r-polymode but didn't get very far.

Example

this is bold in markdown

\center{this centers text} in latex

The latex part should also be highlighted.

Tobias
  • 32,569
  • 1
  • 34
  • 75
ps_r
  • 21
  • 1
  • There is [`(setq markdown-enable-math t)`](https://github.com/nex3/markdown-mode/blob/e4166fcdaaaf1ba912261dbe78bd2e6cd75096b5/markdown-mode.el#L346-L350) for highlighting LaTeX equations in markdown code. But this will not highlight LaTeX command sequences like `\center{...}`. – Tobias Nov 08 '19 at 14:12
  • 1
    I don't think polymode does this. It assumes different languages will be set in different code blocks, or somehow delimited from each other. It doesn't do anything with code in one language inline with code in another. – Tyler Nov 08 '19 at 14:36
  • I had the same feeling about polymode reading the manual. I know of the setting highlighting equations but that, as you say, does not highlight anything else. – ps_r Nov 08 '19 at 16:31
  • Do you also use LaTeX environments like `\begin{align*}...\end{align*}`? Those are far more difficult to handle than other LaTeX command sequences. I think I have a solution for LaTeX command sequences but not for environments. – Tobias Nov 10 '19 at 22:00
  • I usually only need sth like center for beamer presentations and there command sequence would be enough. What would be your solution? I also found a helpful comment suggesting to do this: `(font-lock-add-keywords 'markdown-mode '(("\\(\\\\rightarrow\\)" . font-lock-keyword-face)` Another way would be to use org-mode as there is an org-specific setting to highlight latex. – ps_r Nov 11 '19 at 13:55

0 Answers0