# How to provide good looking TeX output in StackExchange?

I realise that this is not directly concerned with TeX and friends but it is about improving my answers to such questions.

I try and provide an MWE in my answers and I want to show their typeset output which is a PDF file. I have seen that I should use convert file.pdf file.jpg to produce a JPEG file for inclusion in my answer. However when provided in my answer the result looks small and blurry whereas I have seen many other answers with good looking graphics. How could I do that? (I have used GIMP to trim the JPEG files but this only removed irrelevant space and left the poor quality image as it was).

• I prefer the output from the mupdf-tools for the mupdf PDF viewer: e.g., mutool draw -w 900 -o output.png input.pdf Nov 16 '20 at 19:17
• convert has an option -density, try e.g. convert -density 300 file.pdf file.png.
– user228539
Nov 16 '20 at 19:20
• What operating system are you running? Nov 16 '20 at 19:20
• No problem using pdftools from AUCTeX/Emacs. I select the region I want to display, C-TAB and save the image as a png file. (the job is made by Imagemagick) Nov 16 '20 at 19:52
• I use FastStone Image Viewer 7.5 Freeware (Last Update: 2020-03-10) An image browser, converter and editor that supports all major graphic formats including etc ... from faststone.org . Allow the capture of rectangular regions of the pdf viewer so you can zoom to show the issue. Very recommend, no ads. Also has simple tools for editing. Nov 16 '20 at 20:27
• Or FSCapture 5.3 (freeware; went shareware from 5.4) for screen capturing that you can then paste into the question dialog. Nov 16 '20 at 22:32
• I am on windows but I usually just use xpdf and then the windows "snip" tool to highlight a region and paste in, I prefer this to converting the full page display as you can then focus in on the relevant bits. Especially now the site lets you paste in directly from the clipboard so you don't need to save and upload an image Nov 16 '20 at 23:34
• Definitely use PNG, or another lossless format. Maybe SX will someday allow SVG. Nov 17 '20 at 1:22
• GhostScipt, ImageMagick (which uses gs) and pdftocairo are all good conversion programs. Nov 17 '20 at 1:24
• I think this belongs in the meta, dunno if OPs can move it there. As for the question: I just use screen captures Nov 17 '20 at 8:42
• Screen captures in PNG format and enough zoom in the PDF viewer will be enough in most cases. If you want capture a big area that does not fit in the screen with enough zoom, then the solution is a PDF to PNG conversion but taking care of the final resolutions, i.e., of the pixels per inch in the web page (not in the source image).
– Fran
Nov 17 '20 at 9:15
• I'm on a Linux system, and I use the manual equivalent of the recipe given here: tex.meta.stackexchange.com/a/3675 More possibilities are given in answers to this question: tex.meta.stackexchange.com/q/5954 Nov 17 '20 at 15:02
• Thanks to everybody who provided a comment. There seem to be several approaches and it will take me a little while to try them all out. At the moment convert -density 300 F.pdf F.jpg followed (or preceeded) by a crop looks OK. Nov 17 '20 at 18:34
• @PeterWilson is it possible to show a real world example to show the problem and the comparison which is better -- I am also interested in improving my answers Nov 18 '20 at 1:45
• For output containing text avoid using JPEG, that one was made for photo-compression and tends to have bad artifacts. Nov 18 '20 at 19:24

SX allows displaying embedded SVG, but does not provide an SVG upload facility itself. Thus, the SVG needs to be installed on a long-living, personal web page or third-party hosting service.

I chose GitHub Pages and created a minimal project page from a GitHub repository according to the given instructions. SVG files, later committed to this repository, are readily accessible by their URL. Another option could be https://svgshare.com, that allows SVG uploads without registration, but I am unsure about its reliability.

To display an SVG on SX, embed the SVG URL in an img tag:

<img src="https://agrahn.github.io/mysvgs/svg/integral.svg" width="300"/>


A useful tag attribute is width, without which the image is scaled to text width.

The SVG was produced with

latex example
dvisvgm --exact --font-format=woff2 --zoom=-1 example


from input

\documentclass[varwidth]{standalone}

\begin{document}
$\int_0^1 2x\,\mathrm{d}x=1$
\end{document}


The chosen dvisvgm options ensure accurate cropping to the content, embedding the needed font glyphs in a web-browser compliant format, as well as scalability via the img tag's width attribute.

• This is good to know, but it has disadvantages. Since you can’t upload the SVG, this could someday lead to broken image links in your answer. It’s also possible to inadvertently create a SVG that displays fine on your computer, but breaks for someone else who doesn’t have the font installed. (Or where it works for someone with a different version of the font, so they can’t see what the problem is.) Nov 20 '20 at 18:48
• The font is not an issue, as it is embedded in the SVG. But the problem of broken links indeed remains. Nov 20 '20 at 19:19
• You properly embedded the font in the SVG, but it’s entirely possible to create a SVG that doesn’t embed all its fonts. And the poster would have no way of noticing the mistake, because it would display properly for them. Nov 20 '20 at 19:33
• They would very likely be notified via the commenting function. Nov 20 '20 at 19:54
• Unless the SVG works for most readers, but not all, or only breaks on a different version of the font years later. If the site allowed SVG uploads, it could in theory check the file and accept only ones that embed all their fonts. Nov 20 '20 at 20:02
• Doesn't most SVG editors allow glyph conversion to paths? That would fix the font problem as well. Nov 20 '20 at 21:28
• There is no problem at all; the font can be embedded with --font-format=woff2, or converted to paths with --no-fonts options. Both make the SVG self-sufficient. Nov 20 '20 at 21:37
• @Davislor All this sounds rather far-fetched. If the poster correctly uses the available tools, as suggested in the answer, the SVG is self-sufficient. Then, the only potential problem that remains is broken links, which can be minimized by using a reliable and longliving hosting service, GitHub, for instance. Nov 20 '20 at 21:51
• It’s definitely easy to make a correct SVG! It’s possible to make one that breaks, though. If we could upload SVGs, the site could check that they’re correct. Nov 20 '20 at 23:12
• The possibility of direct SVG upload with automatic compatibility check is of course desirable. Nov 23 '20 at 8:49
• I cannot see the image on my browser (Chromium). The image link also shows 503 Over Quota. Nov 24 '20 at 6:14
• @ApoorvPotnis : Works for me. Maybe svgshare.com was temporarily unavailable. Nevertheless, I edited the answer, using GitHub Pages now. Nov 24 '20 at 11:46
• Thanks for addressing. I can see both the images now. Nov 24 '20 at 17:23