TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have code snippets on my github account and I'd like to import the code from them directly into my LaTeX document via something like:


Is this possible? I've searched everywhere but cannot find this.

share|improve this question

LaTeX itself has no download or any other Internet functionality, so you can't import website etc. directly. You can however download the text and import it using \input{<localfile>} into your document. However, if it is source code you need to use a verbatim package like listings. With it you can use \lstinputlisting[<options>]{<filename>}. In the options you can also specify language=.. to get syntax highlighting.

In theory it would be possible to write an import macro which does this all for you, i.e. downloads the source code and includes it correctly, but I don't think someone programmed it yet. This would require to call external software from within LaTeX, which is only possible when the -shell-escape compiler option is used.

share|improve this answer
I guess something similar to the ConTeXt Mk IV approach for external graphics would be a possibility, as that avoids needing shell-escape by using Lua. – Joseph Wright May 8 '12 at 8:17
@JosephWright: I've made some attempts with LuaTeX and the LuaSocket library. In general, socket.http.request works for fetching the content of any link, but always over the HTTP protocol. Sadly, GitHub provides access to raw versions of the public gists only over HTTPS. In this specific case, socket.http.request will fail (at least it failed with me). – Paulo Cereda May 8 '12 at 12:29

As Joseph mentioned, it's easy with ConTeXt. The macro \locfilename points to a local (cached) version of the web resource of the argument, which you can use as every other local file.

\locfilename {http://www.example.com/sometexfile.tex}

Since you want to print external text, you can make use of the ConTeXt vim module, which has this functionality built in. Use:

\usemodule [vim]
\definevimtyping [LATEX] [syntax=latex]


This results in a page containing the source of the tufte-handout class. This mechanism work with several protocols, including https.

Note: URLs are sometimes nasty in TeX. When you run into problems with characters of the wrong catcode, you can use \asciimode, which turns everything except the backslash into a character.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.