Latex rendering (another thread)

In summary, the latex engine seems to go haywire halfway through a 'display math' section delimited by double dollars. In the same post, with the PF-specific breakouts for in-line tex converted to latex standards, the code works perfectly in my offline latex engine. However, 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!), the board software has to be able to handle badly nested tags somehow. Adding spaces around the i works: ##[ i ]##.
  • #1
andrewkirk
Science Advisor
Homework Helper
Insights Author
Gold Member
4,119
1,716
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:
Physics news on Phys.org
  • #2
I think your problem is with [x], where x stands for i.
Adding spaces around the i works: ##[ i ]##.
 
  • Like
Likes ProfuselyQuarky and andrewkirk
  • #3
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]?
 
  • Like
Likes andrewkirk
  • #4
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
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
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]$$
 
  • Like
Likes ProfuselyQuarky and Greg Bernhardt
  • #7
mfb said:
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
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
mfb said:
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
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
andrewkirk said:
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
micromass said:
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
ProfuselyQuarky said:
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.
 
  • Like
Likes dlgoff
  • #14
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
andrewkirk said:
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.
 
  • Like
Likes andrewkirk
  • #16
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.
 
  • Like
Likes Greg Bernhardt
  • #17
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.
 

1. What is Latex rendering?

Latex rendering is the process of converting mathematical equations written in Latex syntax into visual representations, typically in the form of images or PDF files. It is commonly used in scientific and academic publications.

2. How does Latex rendering work?

Latex rendering involves several steps, including parsing the Latex code, converting it into a tree structure, and then rendering the equations using a specialized program or library. The resulting images or PDF files can then be inserted into a document or webpage.

3. What are the benefits of using Latex rendering?

One of the main benefits of using Latex rendering is the ability to create high-quality equations and symbols that are difficult to reproduce using regular text or word processing programs. Latex also allows for precise formatting and consistent rendering across different devices and platforms.

4. Can I use Latex rendering in my own work?

Yes, Latex rendering is a widely available tool and can be used by anyone with basic knowledge of Latex syntax. There are also many online resources and tutorials available to help beginners get started with using Latex for equation rendering.

5. Are there any limitations of Latex rendering?

While Latex rendering is a powerful tool for creating equations, it does have some limitations. For example, it may not be suitable for more complex diagrams or graphics. Additionally, some web browsers may not support Latex rendering, so alternative methods may need to be used for online publishing.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
265
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Special and General Relativity
3
Replies
94
Views
8K
Replies
6
Views
13K
Back
Top