*the thing you see in the PDF/DVI when you compile the LaTeX code.

• Usually you use the standalone class to get a 'focussed' PDF, then convert using a tool of your choice to .png format. Which operating system do you use? – Joseph Wright Sep 26 '12 at 10:54
• You know I was referring to adding an output on a question/answer on tex.SE, right? I'm using Windows 7 but isn't there a tool to do such a thing on tex.SE, i.e. that will be OS-independent? – User 17670 Sep 26 '12 at 12:02
• Compiling a .tex file to output needs a TeX system, and there is not one available via the 'back end'. Moreover, many issues depend on particular versions of packages or similar, and so need to be compiled 'locally' (on a known set up, which a remote server would not be). On Windows, I would use IrfanView to convert the PDF to .png (needs GhostScript installed). There is a question on the main site about this: various approaches are possible. – Joseph Wright Sep 26 '12 at 12:13
• An easy way to avoid converting the file is to simply make a screenshot of the PDF opened in a PDF reader. – ℝaphink Sep 26 '12 at 12:20
• Also I'm using this addon for Firefox which also has a standalone version for generic use : addons.mozilla.org/en-US/firefox/addon/lightshot – percusse Sep 26 '12 at 12:25
• The image hosting site can also take PDFs directly (though the resolution is sometimes not high enough). – Loop Space Sep 26 '12 at 12:26
• there are some possibly useful suggestions in the answers to this question. – barbara beeton Sep 26 '12 at 12:59
• – Werner Sep 26 '12 at 16:08
• – doncherry Sep 26 '12 at 16:59
• Under Windows, the last freeware version of FastStone Capture - v5.3 is very easy to use. It has a built-in editor. – Werner Dec 21 '15 at 19:44

Here's my method, on Windows. Your mileage may vary:

1. Nothing against it, but I use the "appropriate" document class rather than standalone.

2. I open the result in my PDF reader, at 100%

3. I take a screen shot (usually a subrectangle of the whole window), using MWSNAP, and save it (automatically) as a .png for uploading

4. When, occasionally, the output is too big for a convenient screen capture, my PDF reader, PDFXCHANGE Viewer, allows me to export the .pdf to a number of different graphic formats, at a chosen, appropriate DPI resolution, again for uploading.

• Windows 7 also has a snipping tool. – Werner Nov 23 '12 at 22:22
• @werner : True. But I've used MWSNAP for years, now. The nice thing I think it has over the MS snipping tool is autosave with a timestamped filename... – Brent.Longborough Nov 24 '12 at 11:44
• StackExchange now allows to directly paste to include an image. Perhaps you can add that (it avoids saving to disk and uploading). – Werner Apr 3 '13 at 3:20
• @Werner I must be a bit dumb, because I couldn't make that work. In MwSanp, Edit -> Copy, then in SE Paste doesn't do anything...? – Brent.Longborough Apr 3 '13 at 10:23
• You still have to "Insert image..." (or Ctrl G), then paste. Still no luck? – Werner Apr 3 '13 at 14:13
• @Werner No, Ctrl-G just opens a small dialogue (File or Web). Os this a browser catch? I use Firefox. Ah, but do you paste the image, or the image path and filename? – Brent.Longborough Apr 3 '13 at 19:22
• You paste the image, not the path. As mentioned, it avoids savings something to disk before uploading. If you can see "(or paste or drag-and-drop)" in your Ctrl-G dialog, then you should be able to paste. If not, then it may be browser dependent. The original release of this features was mentioned in Recent feature changes to Stack Exchange, and references Upload images by drag-and-drop. There seems to be no mention of it being browser-specific, AFAIK. – Werner Apr 3 '13 at 19:34
• In Chrome, the dialogue box includes the word "paste", and you can. In Firefox, it doesn't and you can't. Sorry, I'm not going to buy a 100-Gb-of-RAM PC to be able to run Chrome just for that... – Brent.Longborough Apr 3 '13 at 19:52

My method, on Mac OS X.

Sometimes I use \usepackage[convert,border=2]{standalone}, which requires pdflatex --shell-escape and that ImageMagick is installed (it is if one has a full MacTeX distribution). This has a limitation, because not everything can be obtained just as if a real class were used.

So most of the times I compile the document with the proper class, open the PDF at full screen and take a snapshot with the system tool: Command-Shift-4 allows to choose a rectangle and writes a PNG (72 dpi) on the desktop.

Hopefully my answer below is still useful for you and others, especially for Windows users.

## Theory

Once you have had a PDF output, you need to convert it to PNG by using the following batch file named pdf2png.bat. It is convenient to register the batch path to the system variable.

rem pdf2png.bat
echo off
rem %1 PDF filename without extension
rem %2 density
rem %3 alpha, choose one of {on,off,remove}

del "%~1-*.png"

convert -compose copy -bordercolor red -border 3x3 -density %2 -alpha %3 "%~1.pdf" "%~1-%%02d.png"


Notes:

• %1 is the first mandatory argument that specifies the filename (without extension) of your PDF to convert.
• %2 is the second mandatory argument that specifies the density. The higher density makes the PNG dimension larger.
• %3 is the third mandatory argument that specifies whether or not you preserve the transparency. Use on if you want to preserve the transparency, otherwise choose remove. I don't use off because it produces a lousy output.
• I added an additional feature such that the output will be enclosed by a red rectangle. If you don't like this feature, remove -compose copy -bordercolor red -border 3x3 from the code above.

## Exercise

It is just an example. Your scenario in which you get a PDF might be different from mine. My scenario is as follows: compile the following input file with latex->dvips->ps2pdf to get a PDF output.

% myfilename.tex

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[showgrid](4,3)
\pstGeonode[
PointName=none,
PointSymbol={x,none,x},
dotscale=2]
(0,0){A}
(1,3){B}
(4,1){C}
\psline(A)(B)(C)
\end{pspicture}
\end{document}


You can invoke the batch from the editor of your choice, but here I invoke the batch from the DOS prompt:

The output is:

The red rectangle is the border produced by -compose copy -bordercolor red -border 3x3.

• I made a duplicate here. – kiss my armpit Nov 13 '13 at 18:59
• For Windows users, the convert alone no longer works. Instead it must be preceded by both magick and a space because convert has a special meaning in Windows. – Artificial Stupidity Nov 14 '18 at 16:25

In TeXmaker Cross-platform Editor, Starting from Version 3.4 It is easily possible to export a .png image from the internal pdf viewer with simple right click on the current .pdf page.

Screenshot for .png preparation from .pdf using TeXmaker: Zoom your browser to see closer to code

ShareX Tool

This tool allows you to quickly capture portions of your screen, automatically uploads the screenshot to imgur.com, then automatically copies the imgur link to your clipboard. All you need to do is press CTRL+V wherever you need it.

Personally, made the hotkeys such that...

• CTRL+SHIFT+Z: Capture of piece of the screen.
• ALT+PRTSC: Capture the current window.

You can have the ShareX automatically copy the filepath, the image, the file, etc. It may also be possible to configure ShareX to upload to a specific imgur account automatically.

I use this tool constantly. Cheers~

• Does this allow use of the correct Imgur account (the paid-for StackExchange one)? – Joseph Wright Jul 6 '13 at 5:44

Maybe this could be useful for someone: the convert command of ImageMagick has an option which allows you to cut out the written part of an image: -trim +repage.

If you use arara package you may use a rule like this to do the conversion automatically.

For example if you have this myfile.tex (I've setted the background to red only to show the trimming):

% arara: pdflatex
% arara: convert: {background: red, otheroptions: -trim +repage}
\documentclass{book}
\pagenumbering{gobble}
\begin{document}
Quack
\end{document}


and you run:

arara myfile,tex


you will get this myfile.png:

Of course, you can get the same result if you have myfile.pdf and run:

convert -background red -alpha remove -density 150 -trim +repage "myfile.pdf" -quality 100 "myfile.png"


In the particular case of a beamer question with overlays, it is often useful to attach the output in the form of an (animated) GIF.

The answer to that (brought to me courtesy of @Schrödinger'scat) is that you can use convert from ImageMagick.org: convert -density <density> -delay <delay> -loop 0 -alpha remove multipage.pdf animated.gif, as explained in this answer.

I'm just adding this here in case someone else is looking for this little piece of magic. :)

On OSX, try LaTexIt, which comes with MacTeX.

You will want to copy the essentials of your preamble to the the "document preamble" (which can be made visible by choosing LaTeX->Show preamble).

Then, copy the essentials of what lies between \begin{document} and \end{document} into the main box. (If it is an equation, the best is to copy what lies between the delimiters and select the appropriate environment.)

An image can then be easily exported or copied to the clipboard.