LaTeX ActionScript 3 Listings Preset

Today I’ve been looking for a way to print my code efficiently for my bachelor project. I use to copy paste everything but from now on this is a thing of the past. I decided to use LaTeX to format my code as it can pretty much do everything else.

I found a package that could help me print my code: listings

Now, there is no preset yet for ActionScript and apparently no Flex or Flash coder uses LaTeX frequently and is willing to share his preset. This forced me to create one myself and here is the result:

% Colors used by Flex Builder 3.
\definecolor{purple}{rgb}{0.65, 0.12, 0.82}
\definecolor{flexred}{rgb}{0.65, 0.01, 0.01}
\definecolor{flexgreen}{rgb}{0, 0.6, 0}
\definecolor{flexgray}{rgb}{0.25, 0.37, 0.75}
\definecolor{flexblue}{rgb}{0, 0.2, 1}
\definecolor{flexfunction}{rgb}{0.2, 0.6, 0.4}
\definecolor{flexvar}{rgb}{0.4, 0.6, 0.8}

% Define new language for listings.
\lstdefinelanguage{ActionScript} {
	basicstyle=\ttfamily\scriptsize,
	sensitive=true,
	morecomment=[l][\color{flexgreen}\ttfamily]{//},
	morecomment=[s][\color{flexgreen}\ttfamily]{/*}{*/},
	morecomment=[s][\color{flexgray}\ttfamily]{/**}{*/},
	morestring=[b]",
	stringstyle=\color{flexred}\textbf,
	commentstyle=\color{flexgreen},
	showstringspaces=false,
	numberstyle=\scriptsize,
	numberblanklines=true,
	showspaces=false,
	breaklines=true,
	showtabs=false,
	emph =
	{[1]
		class, package, interface
	},
	emphstyle={[1]\color{purple}\textbf},
	emph =
	{[2]
		internal, public, protected, private,
		super, this, import, new, extends, implements,
		void, true, false, as
	},
	emphstyle={[2]\color{flexblue}\textbf},
	emph =
	{[3]
		function
	},
	emphstyle={[3]\color{flexfunction}\textbf},
	emph =
	{[4]
		var
	},
	emphstyle={[4]\color{flexvar}\textbf}
}

All you have to do is load the listings package, set the language to ActionScript and insert your source files. Here is an example:

% Load the listings package.
\usepackage{listings}

% Set the preset of listings to ActionScript, defined above.
\lstset{language=ActionScript}

% Use this command to insert source file
\lstinputlisting{path/to/file.as}

% Use this command to format code
\begin{lstlisting}
ActionScript Code
\end{lstlisting}

This preset can be used to format ActionScript files and mxml files, although the latter is not fully supported, just the ActionScript between the <mx:Script> tags. If somebody has some additional code to support mxml, please let me know. I didn’t add this feature because I tend to avoid using mxml files.

Enjoy!

VN:F [1.7.7_1013]
Rating: +2 (from 2 votes)
22 Comments
May 23, 2009 in Integrated Project, Uncategorized
Tagged , , ,

22 Responses

  1. Hello,
    Like you, I’m a student writing a Flex app as my final project, and I have to document it using LaTeX… this is just what I was looking for, thanks a lot! :D

  2. Thank you!!!! I’m also writing a Flex app for my bachelor project, and the highlighter is exactly that, what I was looking for since month ;)

    Greets from germany!

  3. Thanks a lot for sharing! I made an MXML version based on yours – it’s not 100% looking like in FlexBuilder, but almost. Maybe someone can add what’s missing to make it 100% ;)

    go this way to the LaTeX MXML Preset

    Also greetings from Germany :D

  4. Thanks a lot for your work. Just what I needed!

  5. Hello, can you help me??
    I want to use your source code but im beginner in latex.. how can do it??it said, i have several files in my latex project: file.cls, file.txt..
    do you know what parts of code i have to add into file.cls and into file.txt??
    I hope your answer…thank you

  6. Your blog is very interesting. May i write article for you, could you publish it here ? Please mail me

  7. Good work, keep us posting, you are very good writer.

  8. I wanted to thank you for this great read!! I definitely enjoying every little bit of it smile I have you bookmarked to check out new stuff you post.

  9. Is this cms you use good for my first site ? I want to start blogging soon and looking for good platform.

  10. Excellent article i am sure that i will come back here soon

  11. Thanks for writing this post. Now everything is clear for me.

  12. I was extremely in seventh heaven to find this site.I wanted to offer you with a view this enormous read!! I definitely enjoying every ungenerous bit of it and I hold you bookmarked to thwart revealed novel stuff you post.

  13. You post great posts. Bookmarked !

  14. I’m sure that i will come back to your site soon. Keep us posting interesting articles

  15. Great info, thanks for useful post. I am waiting for more

  16. You post great posts. Bookmarked !

  17. Hi webmaster – This is by far the best looking site I’ve seen. It was completely easy to navigate and it was easy to look for the information I needed. Fantastic layout and great content! Every site should have that. Awesome job

  18. Aw, this was a really quality post. In theory I’d like to write like this also – taking time and real effort to make a good article… but what can I say… I procrastinate alot and never seem to get anything done… Regards…

  19. This is a great site.  Good clean interface and nice informative articles. I will be coming back in a bit, thanks for the great article.

  20. I was doing a search about this subject, and happened to come across your post. I’m thankful for your blog. I am going to spend time exploring, and will absolutely be bookmarking this one. You do have a excellent way with words, and you also chose a great layout to go with the site. Maintain the great work as you have converted me into a frequent reader.

  21. Thx !! :)
    ……………….

Leave a Reply

Spam Protection by WP-SpamFree

Using Gravatars in the comments - get your own and be recognized!

XHTML: These are some of the tags you can use: <a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>