0

I plan to publish latex code on WordPress. My VPS has a full installation of texlive and my WordPress will call xelatex or pdflatex to generate pdf, and my WordPress will also call pandoc to generate html.

I am new to WordPress (plugin) development, but I guess my workflow can be implemented as a custom post.

register_post_type( 'latex_page', 
array('supports'=> array( 'title', 'editor'),
      ...
));

This piece of code adds 'editor' to the supports option, and users will write their latex code in the WordPress editor.

But the WordPress editor by default is Gutenberg editor. Its block style is completely useless for a latex file. Even if I switch to the classic editor, the <b>, <i> buttons and the like are not necessary.

What's more, the edit page displays an "Add Media" button. The logic of the "Add Media" button doesn't work with Latex. Latex uses the syntax like \includegraphics[width=1em]{github.png}, but the "Add Media" button adds the code <a href="github.png"><img src="github.png></a>. To avoid complexity, for now I do not want to allow users to use includegraphics.

I am a mathematician. So by definition, what is the WordPress editor? What content does it suppose to edit?

I figure rather than disabling everything in the feature-rich editor, why don't I just use a plain text custom field to hold latex code?

1 Answer 1

1

The editor enables you to enter either plain text or HTML content to a post/page body. The content is saved to post_content column on the wp_post database table.

When rendering the content WordPress runs it through a few filters to automatically add <p> tags, capitalize P in Wordpress, etc. If the content contains shortcode markup (i.e. square brackets stuff) or block related HTML comments, then WordPress will parse those into HTML - assuming the shortcodes and blocks have been registered properly.

Yes, if you want more control, you can register a custom metabox (or a block) with a plain textarea for the latex code. You can even go wild and disable the default editor completely, register a custom metabox with a textarea named "content" and have the latex code saved automatically to the post_content column instead of a post meta field.

1
  • Shortcodes are a good point. I feel shortcodes are like \newcommand in Latex so I don't need shortcodes either. I will go disable WordPress editor and use a plain textarea for my latex code. Thank you!
    – Gqqnbig
    Commented Jun 20 at 5:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.