As @paul-gessler has commented, this has been asked several times before, and the community of TeX.SE is generally against such a feature, mostly because of problems with erroneous code, compatibility, or output that requires multiple files (like bibliographies).
However, I am strongly in favour of this feature, if it is implemented with a separate syntax. In this way a normal code block is be shown as code, which is indeed the most sensible behaviour for this site. However, if the user wants, the output can be shown as well. For example:
# \documentclass{article}
# \begin{document}
# Hello World
# \end{document}
Analogous to the syntax for block quotes.
This would save time for almost every time you post an answer where you want to include a screenshot of the output. Creating a new file, copying the MWE, compiling, making the screenshot, cropping, saving, uploading sometimes takes me more time than answering the question itself (for example with answers like "use \phantom
") and I do this for practically every answer. Another use case is in-line code, like "the $\sum_{\alpha\in\{-5,-10\}\cup\mathbb{Z}^+}$
is not aligned with the $\sum_\beta$
".
TeX.SE could support for example something analoguous to the texlive-full
package in Ubuntu. This supports almost everything. If the result is different from what the OP or the answerer has on his own system, then he can choose to show a screenshot instead. If the question or answer depends on a specific engine, command line options, fonts installed, ..., then a screenshot can be used. But in the many, many cases where the setup doesn't matter, the users can benefit from a compilation feature.
.png
files are easy to add to a question or an answer), and i think that's the most reasonable thing to expect. but it is up to those who are answering questions to "do the right thing".\donotincludeinmaintoc
, that will giveundefined control sequence
, because the package defiing the command would not be loaded.