2

Is there a way to edit and render markdown or any other structured text format and math formulas in C++ code inside VS Code? I want to edit and view text and formulas inside VS Code editor, so there is no need for an external tool to view them in their target format. I know about some support for Doxygen comments, which are rendered in the tooltip, but it's limited and doesn't cover rendering of math formulas inside VS Code.

EDIT

In response to suggestion of having this question closed as redundant to How can I mix LaTeX in with Markdown?. My question is concerned with markdown or any other structured text format and math formulas in C++ code (see above), which is different from editing a pure markdown (*.md) file.

EDIT

In response to comments that my question is still not clear: markdown or any other structured text format and math formulas in C++ code means exactly that. The usual way markdown text is mixed into C++ are specially marked comments, but I'm not limiting my question to that. I would accept illegal C++ syntax, if it is preprocessed into legal C++ code by the build task.

For example, *.cpp file would contain these lines:

// $f(x) = \frac{2 \pi}{x}$
float f(x);

which would be displayed in VS Code editor as:

enter image description here

Paul Jurczak
  • 7,008
  • 3
  • 47
  • 72
  • 1
    Do you mean inside comments in the source? – Some programmer dude Dec 14 '20 at 03:28
  • To my knowledge, Doxygen supports LaTeX embeds which includes support for its math formulae. – paddy Dec 14 '20 at 03:52
  • @Someprogrammerdude Yes, inside VS Code. I edited the question to make it clear. – Paul Jurczak Dec 14 '20 at 04:25
  • @paddy Correct, but Doxygen support is still quite limited and formulas are not rendered at the tooltip. – Paul Jurczak Dec 14 '20 at 04:27
  • Try http://flennerhag.com/2017-01-14-latex/ and https://jekyllrb.com/docs/ maybe ? MathJax is essentially a JavaScript PNG renderer that turn your LaTex Snippets into high quality PNG images. – Soleil Dec 14 '20 at 04:45
  • https://github.com/waylonflinn/markdown-it-katex looks good – Soleil Dec 14 '20 at 04:52
  • @Soleil-MathieuPrévot I know about MathJax, but I don't see a way to use it in C++ code inside VS Code, which is my question. – Paul Jurczak Dec 14 '20 at 05:06
  • @PaulJurczak For any editor, it won't work, you might want to use math symbol in unicode (https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode); it's ugly, but it could be sometime better than latex code; for VScode, however, because it's all js and the code display is actually a webpage, katex seems ideal, and if no one wrote a plugin yet, it might be the opportunity. I'm certain it is possible. – Soleil Dec 14 '20 at 05:10
  • for writing vscode extension: https://code.visualstudio.com/api/get-started/your-first-extension – Soleil Dec 14 '20 at 05:13
  • @Soleil-MathieuPrévot It definitely is possible, but I'm not willing to go that far, not in the near future anyway. – Paul Jurczak Dec 14 '20 at 05:25
  • 1
    Everybody seems to only discuss "inside VS Code" and not "in C++ in VS Code". I think that is because it is not clear what you mean by that. Representing formulas in markdown/math in VS Code is one thing. Using formulas in C++ is something else. Please elaborate the difference you see and what exactly you want to achieve. (Note, I close-voted for lack of clarity, not for duplicate, which I am not convinced of.) – Yunnosch Dec 14 '20 at 07:24
  • @Yunnosch I added en example. I don't think explaining what C++ code means in the context of VS Code. – Paul Jurczak Dec 14 '20 at 09:58
  • 1
    @PaulJurczak You might have your answer, if not an update here: https://github.com/microsoft/vscode/issues/3220 and https://github.com/microsoft/vscode/pull/66418 and https://github.com/microsoft/vscode/issues/85682. What you write in comments is stripped away by the preprocessor, so in a way it's not c++ code, it's code comments in general; extensions doing something similar are language agnostic because of this (they look for a certain regex pattern and then use the IDE api to insert image/html/etc). – Soleil Dec 14 '20 at 23:08

0 Answers0