dosper7 / google-code-prettify

Automatically exported from code.google.com/p/google-code-prettify
Apache License 2.0
0 stars 0 forks source link

Add latex format highlighting #115

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
LaTeX is quite a bit different than anything else, and it is really obvious
when your comments get syntax highlighted instead of the actual commands.
This lang- file is pretty basic but at least makes syntax highlighting
usable for code blocks called out with lang-latex (and also lang-tex).

Something like:

<pre class="prettyprint lang-latex"><code>% resume.tex
% vim:set ft=tex spell:
\documentclass[10pt,letterpaper]{article}
\usepackage[letterpaper,margin=0.8in]{geometry}
\usepackage{mdwlist}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\pagestyle{empty}
\setlength{\tabcolsep}{0em}
</code></pre>

Original issue reported on code.google.com by dpmc...@gmail.com on 4 May 2010 at 6:09

GoogleCodeExporter commented 8 years ago
The previous file I attached had some problems in IE due to trailing commas in 
the
arrays; this version has that fixed.

Original comment by dpmc...@gmail.com on 5 May 2010 at 2:13

Attachments:

GoogleCodeExporter commented 8 years ago
Hi, thank you for this plugin! We are using it with great success at 
http://tex.stackexchange.com -- however it seems there is at least one edge 
condition with it on comments. 

http://meta.tex.stackexchange.com/questions/872/text-immediate-following-double-
backslashes-is-highlighted-as-macro-inside-a-code/874#874

Original comment by wump...@gmail.com on 30 Jan 2011 at 6:58

GoogleCodeExporter commented 8 years ago
This issue mentioned in comment 2 seems to be fixable by changing the regex for 
commands:

from
[PR.PR_KEYWORD, /^\\[^ \r\n{}\[\]=]+/],
to
[PR.PR_KEYWORD, /^\\(\\|[^ \r\n{}\[\]=]+)/],

I tested this with the code linked in comment 2 and it works well.
I attached the updated language file.

Original comment by martin.s...@gmail.com on 30 Jan 2011 at 3:22

Attachments:

GoogleCodeExporter commented 8 years ago
Still works for my purposes and on the original blog post I used this on. 
Thanks for finding and fixing this small issue. Glad the plugin was of help to 
you guys!

Original comment by dpmc...@gmail.com on 30 Jan 2011 at 8:23

GoogleCodeExporter commented 8 years ago
Would it be easier to change this to only match a backslash followed by letters 
and @s. Everything else (usually) ends the control word. And one might 
separately match control characters, i.e. a backslash followed by a single 
non-letter.

Original comment by caram...@gmail.com on 30 Jan 2011 at 8:43

GoogleCodeExporter commented 8 years ago
Here the newly updated file: It now only allows letters, '@' and ':' (for 
LaTeX3 code) and (as requested as a second reges) any one character (for '\\', 
'\%', etc.) after a backslash.

Original comment by martin.s...@gmail.com on 31 Jan 2011 at 10:34

Attachments:

GoogleCodeExporter commented 8 years ago
And here an additional proposal with highlighted declarations (i.e. \def, 
\newcommand and friends) as well '$' and '&' characters. Keywords are same as 
the last one.

Original comment by martin.s...@gmail.com on 31 Jan 2011 at 10:38

Attachments:

GoogleCodeExporter commented 8 years ago
There are a couple of patches floating around.

I'm happy to fold into trunk whichever patch receives the consensus from 
tex.stackexchange.com.  Is there already a consensus or does someone want to 
ask on meta.tex...?

Original comment by mikesamuel@gmail.com on 31 Jan 2011 at 11:40

GoogleCodeExporter commented 8 years ago
Here a small bugfix for the file proposed in comment 7. 
The declaration rule needed a boundary marker at the end.

See 
http://meta.tex.stackexchange.com/questions/872/text-immediate-following-double-
backslashes-is-highlighted-as-macro-inside-a-code/876#876 for the current 
discussion on meta.tex.sx.

Original comment by martin.s...@gmail.com on 1 Feb 2011 at 12:24

Attachments:

GoogleCodeExporter commented 8 years ago
Here my final version. The LaTeX3 support was dropped because it can leads to 
wrong result in normal LaTeX user code. The highlighting of declarations has 
been dropped on demand.

I will open a public vote on tex.sx for this version.

Original comment by martin.s...@gmail.com on 3 Feb 2011 at 3:02

Attachments:

GoogleCodeExporter commented 8 years ago
The last version (10) seems to be the (silent) consensus on 
meta.tex.stackexchange.com.

Original comment by caram...@gmail.com on 10 Feb 2011 at 9:14

GoogleCodeExporter commented 8 years ago
I added the latest version of the patch to trunk.
Martin, I added an apache license header to the top since that's the license 
used elsewhere.  If you're not okay with that, let me know and I'll delete that 
file : 
http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-tex.j
s

See dpmc...'s unittest at 
http://google-code-prettify.googlecode.com/svn/trunk/tests/prettify_test_2.html#
latex

Original comment by mikesamuel@gmail.com on 5 Mar 2011 at 4:22