Latex rendering (another thread)

  • #1
andrewkirk
Science Advisor
Homework Helper
Insights Author
Gold Member
3,792
1,390

Main Question or Discussion Point

In post #4 of this thread the latex engine seems to go haywire halfway through a 'display math' section delimited by double dollars.

The same code, with the PF-specific breakouts for in-line tex converted to latex standards, works perfectly in my offline latex engine. Further, to my surprise, when I pasted the PF-style latex code into a code window (lower down in the same post) that renders it correctly (I wasn't expecting it to attempt to render it at all!).

Does anybody have any idea what's going wrong there?

Also, it may be a useful observation for future reference that a code window renders latex, and seems to do so better than in the normal part of a post!

EDIT: The problem is now solved, thanks to Samy and Ibix, so the problem is no longer visible in that post. It was where a superscript of a symbol within the latex code was the letter i enclosed within square brackets [...]. It was interpreting it as an instruction to start italics, rather than taking it literally as written.
 
Last edited:

Answers and Replies

  • #2
Samy_A
Science Advisor
Homework Helper
1,241
510
I think your problem is with [x], where x stands for i.
Adding spaces around the i works: ##[ i ]##.
 
  • #3
Ibix
Science Advisor
Insights Author
5,955
4,520
You've got an i in square brackets in the maths. I think the forum is reading it as "now start italic text" and breaking the Latex. Since the code tag ignores formatting inside it, it works there.

Change to \left[ i \right]?
 
  • #4
andrewkirk
Science Advisor
Homework Helper
Insights Author
Gold Member
3,792
1,390
Thank you very much Ibix and Samy. I never would have guessed that the 'start italic' code was still operative within a delimited section of latex code. I've followed your suggestions and it all works nicely now.
 
  • #5
Ibix
Science Advisor
Insights Author
5,955
4,520
The board software has to be able to handle badly nested tags somehow. In the context of a public forum it can't just throw a compiler error and sulk in the corner until J Random User figures out how he broke the formatting. Unfortunately it doesn't always do the right thing - particularly in this case where you didn't mean to write a tag at all.
 
  • #6
34,043
9,891
It's something that would require a lot of code changes to fix. The problem is the execution order: the forum software has no idea about LaTeX. It parses the post, finds a "start italic" command and starts italics. It does not know that $$ has a special meaning, it delivers LaTeX formulas as plain text to the user. On the user side then, MathJax (javascript-based) looks for those dollar signs, takes the (forum-delivered) html text between them and tries to interpret it as LaTeX. That fails, because it does not understand the html codes that the forum put in.

Adding spaces is the easiest workaround. $$A[ i]$$ -> $$A[ i]$$
 
  • #7
DrGreg
Science Advisor
Gold Member
2,274
772
The problem is the execution order: the forum software has no idea about LaTeX. It parses the post, finds a "start italic" command and starts italics. It does not know that $$ has a special meaning, it delivers LaTeX formulas as plain text to the user.
I don't suppose it's possible for the forum software to treat LATEX delimiters as if they were a [plain] ... [/plain] pair?
 
  • #8
34,043
9,891
It would be possible to modify it, but I doubt the XenForo developers would include that, as MathJax is not part of XenForo.
@Greg Bernhardt can answer that better.
 
  • #9
18,079
7,499
It would be possible to modify it, but I doubt the XenForo developers would include that, as MathJax is not part of XenForo.
@Greg Bernhardt can answer that better.
The developers won't be interested in this unique request, but I'll add it to my list of custom work to consider.
 
  • #10
andrewkirk
Science Advisor
Homework Helper
Insights Author
Gold Member
3,792
1,390
It would be useful to add to the forum's latex primer a paragraph saying that the user should make sure that latex code does not contain any symbol strings that match BB codes (and explain why), and link to the page that lists them.

It would be similar to the section of the primer currently labelled 'Important Bug'. Actually, maybe it would be good to create a section that lists bugs, perhaps together with a few of the most common user errors. It could be called 'Troubleshooting' in the interests of being more optimistic.
 
  • #11
22,097
3,279
It would be useful to add to the forum's latex primer a paragraph saying that the user should make sure that latex code does not contain any symbol strings that match BB codes (and explain why), and link to the page that lists them.

It would be similar to the section of the primer currently labelled 'Important Bug'. Actually, maybe it would be good to create a section that lists bugs, perhaps together with a few of the most common user errors. It could be called 'Troubleshooting' in the interests of being more optimistic.
There's a lot of things I want to change in my LaTeX primer, but sadly I don't have the powers to do it anymore. I think only Greg can change those tutorials nowadays.
 
  • #12
ProfuselyQuarky
Gold Member
814
526
There's a lot of things I want to change in my LaTeX primer, but sadly I don't have the powers to do it anymore. I think only Greg can change those tutorials nowadays.
What would you change?
 
  • #13
22,097
3,279
What would you change?
There is many outdated advice from when the old forum software was used, and there is a lot of new stuff with the current forum software that isn't described in the tutorial. For example, the entire paragraph on the "character limit without spaces" needs to be removed. I'll just try to get the code, change it and send it to Greg. He'll upload it then. I'll change the other FAQs too since they're outdated too.
 
  • #14
andrewkirk
Science Advisor
Homework Helper
Insights Author
Gold Member
3,792
1,390
I think it would be excellent to update the LaTeX primer. It certainly is a little dated now. Various ideas for useful inclusions have come to me from time to time. Ones that I can remember off the cuff are:

1. Obviously (because it's most recent) the above issue about making sure the latex code does not inadvertently contain any BB codes.

2. The great trick that I saw in somebody's post recently for writing raw latex code into a post for people to read, without it getting rendered. That is to change the colour of the delimiters to black (rather than automatic), thereby using the previous bullet point in a constructive way to disrupt the rendering. eg ##\pi##, $$\pi$$

3. The fact that the standard latex delimiter $ to open and close in-line latex does not work on the forum (presumably to stop latex rendering inadvertently, and unwantedly, when somebody is writing about dollars), and that the simplest replacement is ##.

4. The neat regular expression that somebody wrote that can in a single editor command (in a suitably competent editing program) convert standard latex to PF-latex by changing all single dollars (but not if they're in a double dollar) to double-hash symbols. I don't have the expression to hand but it could easily be dug up or recreated.

5. The alternative of, when preparing latex off-line for posting to PF (the only reasonable way to do it for any non-trivial calculations, IMO), using the other standard \( and \) asymmetric delimiters for in-line latex, which can then be converted to the PF-latex asymmetric delimiters [itex] and [/itex] by two very basic search and replace commands, without having to remember the fancy regex command from point 4. This alternative has the additional advantage that, because it does not use regexes, one can do it in any editor, even (Gasp!) Microsoft Notepad.

6. Showing links to free, open-source latex programs such as TeXmaker, TeXworks, Miktex, MacTex, that people can use both to learn latex, develop proficiency and prepare non-trivial mathematical posts for posting to PF.
 
  • #15
34,043
9,891
4. The neat regular expression that somebody wrote that can in a single editor command (in a suitably competent editing program) convert standard latex to PF-latex by changing all single dollars (but not if they're in a double dollar) to double-hash symbols. I don't have the expression to hand but it could easily be dug up or recreated.
Replace (^|[^\\$])\\$([^\\$]|$) by $1##$2.
Note how both ^ and $ are used in two different contexts.

Those things can be mentioned somewhere under "advanced", they are certainly not the basics any more.
 
  • #16
jtbell
Mentor
15,518
3,352
Mentors have the ability to add or edit the help pages, and I've started working on the LaTeX primer. Unfortunately, it will take a while to finish the job. I'm basically writing it over from scratch. In our old forum software, the help pages were written the same way as ordinary posts, using BBcode tags for formatting. The current software uses HTML tags for formatting help pages. Greg apparently ran the old help pages through a converter, or maybe he simply copied and pasted the HTML code that the old software generated. The result is very clumsy and hard to work with for editing. Therefore I decided to start from scratch, coding the HTML by hand. You can see the current state of this project at the bottom of the list of "Help/How-To" pages.
 
  • #17
34,043
9,891
You can use the forum itself as BBcode->HTML converter for most things, but there are also many converters available on various websites.

Writing directly in HTML is more powerful of course.
 

Related Threads on Latex rendering (another thread)

  • Last Post
Replies
9
Views
747
  • Last Post
Replies
6
Views
4K
Replies
14
Views
2K
Replies
1
Views
3K
  • Last Post
Replies
5
Views
4K
  • Last Post
Replies
9
Views
717
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
8
Views
2K
  • Last Post
Replies
5
Views
9K
  • Last Post
Replies
2
Views
4K
Top