Welcome to our community

Be a part of something great, join today!

Syntax highlighting [INSTALLED, WAITING ON FEEDBACK]

dwsmith

Well-known member
Feb 1, 2012
1,673
Can syntax highlighting be implemented when we use the code tags? The code in the tags would be easier to follow with the eyes if we had such a feature.
 

Jameson

Administrator
Staff member
Jan 26, 2012
4,042
Re: syntax highlighting

Using the PHP tags will highlight some, although I'm not sure if it's exactly what you're looking for.
 

dwsmith

Well-known member
Feb 1, 2012
1,673
Re: syntax highlighting

Using the PHP tags will highlight some, although I'm not sure if it's exactly what you're looking for.
Something like this:

 

Jameson

Administrator
Staff member
Jan 26, 2012
4,042
Re: Syntax highlighting

Sorry to get back to you a bit late on this but I'm on vacation.

I still believe the PHP BBcode button will do the trick. How does this look?

PHP:
<html>
<body>

<?php
if (isset($_COOKIE["user"]))
  echo "Welcome " . $_COOKIE["user"] . "!<br>";
else
  echo "Welcome guest!<br>";
?>

</body>
</html>
 

Ackbach

Indicium Physicus
Staff member
Jan 26, 2012
4,192
Re: Syntax highlighting

Sorry to get back to you a bit late on this but I'm on vacation.

I still believe the PHP BBcode button will do the trick. How does this look?

PHP:
<html>
<body>

<?php
if (isset($_COOKIE["user"]))
  echo "Welcome " . $_COOKIE["user"] . "!<br>";
else
  echo "Welcome guest!<br>";
?>

</body>
</html>
I could be wrong, but I think dwsmith is talking about typing up $\LaTeX$ code on this forum, and when we do that, it is helpful to have syntax highlighting in the editor so as to see where there are problems.

PHP:
$$\int_{- \infty}^{ \infty}e^{-x^{2}} \, dx= \sqrt{ \pi}.$$
Wrapping $\LaTeX$ code with php tags gives some syntax highlighting, but only in the post, and not in the editor.
 

Jameson

Administrator
Staff member
Jan 26, 2012
4,042
Re: Syntax highlighting

Hmm, if that's the case then I would say that one can simply hit "Preview" to check the code in the editor but that's not really needed. If there are problems with Latex syntax, Mathjax will not render the bit in question or will render it but highlight a problem in red. I think coding some sort of immediate Latex syntax checker into the editor would be a large project.
 

dwsmith

Well-known member
Feb 1, 2012
1,673
Re: Syntax highlighting

Hmm, if that's the case then I would say that one can simply hit "Preview" to check the code in the editor but that's not really needed. If there are problems with Latex syntax, Mathjax will not render the bit in question or will render it but highlight a problem in red. I think coding some sort of immediate Latex syntax checker into the editor would be a large project.
PHP highlighting removes \ from the code and who knows what else it may remove that would affect compiling of the Latex code. I would like the highlighting so if I post a chunk of code, it is easier for people to read.

For instance, take my post here, this looks horrible to read unless you copy to your own editor. If we had highlighting, people could easily follow it from the site.
 
Last edited:

Jameson

Administrator
Staff member
Jan 26, 2012
4,042
Re: Syntax highlighting

I might have found something we can use, but it needs to be tested more. There is syntax-highlighting freeware called Geshi and someone wrote a vBulletin plugin for it. It has functionality for a bunch of languages, including $\LaTeX$. Here is what it looks like when in use. What do you think?

Screen Shot 2013-07-24 at 11.23.07 AM.png
 

dwsmith

Well-known member
Feb 1, 2012
1,673
Re: Syntax highlighting

I might have found something we can use, but it needs to be tested more. There is syntax-highlighting freeware called Geshi and someone wrote a vBulletin plugin for it. It has functionality for a bunch of languages, including $\LaTeX$. Here is what it looks like when in use. What do you think?

View attachment 1076
When will it be implemented?
 

Jameson

Administrator
Staff member
Jan 26, 2012
4,042
Re: Syntax highlighting

Testing that this works.

[LATEXS]% Example LaTeX document for GP111 - note % sign indicates a comment
\documentstyle[11pt]{article}
% Default margins are too wide all the way around. I reset them here
\setlength{\topmargin}{-.5in}
\setlength{\textheight}{9in}
\setlength{\oddsidemargin}{.125in}
\setlength{\textwidth}{6.25in}
\begin{document}
\title{LaTeX Typesetting By Example}
\author{Phil Farrell\\
Stanford University School of Earth Sciences}
\renewcommand{\today}{November 2, 1994}
\maketitle
This article demonstrates a basic set of LaTeX formatting commands.
Compare the typeset output side-by-side with the input document.[/LATEXS]

Before I make any announcement about this, is this highlighting pattern good enough for us to use long term?
 

dwsmith

Well-known member
Feb 1, 2012
1,673
How do we make use of it? Is there a button for it?
 

Jameson

Administrator
Staff member
Jan 26, 2012
4,042
How do we make use of it? Is there a button for it?
I was holding off on explaining this until I got positive feedback. For now you must type out the BBCode tags:

[LATEXS]...[/LATEXS]

(the "S" stands for source code and using this convention will make knowing the BBCode tag for another programming language easy - the name of it with an "S")

I can change this though and if we want to choose a different tag name then we should decide that now. Once we do that I can work on adding a button to the toolbar.
 

Chris L T521

Well-known member
Staff member
Jan 26, 2012
995
I was holding off on explaining this until I got positive feedback. For now you must type out the BBCode tags:

[LATEXS]...[/LATEXS]

(the "S" stands for source code and using this convention will make knowing the BBCode tag for another programming language easy - the name of it with an "S")

I can change this though and if we want to choose a different tag name then we should decide that now. Once we do that I can work on adding a button to the toolbar.
I think TEXSRC (TeX Source Code) would be a better bbtag, but that's just me; it just flows better in my head.
 

dwsmith

Well-known member
Feb 1, 2012
1,673

Jameson

Administrator
Staff member
Jan 26, 2012
4,042
Hmm, that thread looks perfect now to me. Is it fixed on your end as well?
 

dwsmith

Well-known member
Feb 1, 2012
1,673
Hmm, that thread looks perfect now to me. Is it fixed on your end as well?
It is not fixed on my end--still looks the same.
 

Jameson

Administrator
Staff member
Jan 26, 2012
4,042
This highlighting doesn't except $ signs. See here. I had to add \ to force it but that is improper code.

http://mathhelpboards.com/questions...s-adding-our-own-commands-6228.html#post28316
I don't know why this new highlighting function doesn't work well with you and your computer but it works perfectly on 3 computers that I've tried. The dollar sign doesn't seem to be a problem either.

[LATEXS]\newcommand{\bfg}[1]{\mbox{\boldmath$#1$}}[/LATEXS]
How does that look to you? To me there aren't any errors.
 

Klaas van Aarsen

MHB Seeker
Staff member
Mar 5, 2012
8,779
I don't know why this new highlighting function doesn't work well with you and your computer but it works perfectly on 3 computers that I've tried. The dollar sign doesn't seem to be a problem either.

[LATEXS]\newcommand{\bfg}[1]{\mbox{\boldmath$#1$}}[/LATEXS]
How does that look to you? To me there aren't any errors.
It works for me.
 

MarkFL

Administrator
Staff member
Feb 24, 2012
13,775