Sublime与Python:如何用Python插件将Scientific Workplace公式转为规范LaTeX格式
Hey there, let's sort out that frustrating eqnarray* issue right away! First off, quick heads-up: eqnarray is actually deprecated in modern LaTeX because it creates wonky, inconsistent spacing—we want to use align* from the amsmath package instead, which is the standard for multi-line equations.
Here's how to tweak your Sublime Python plugin to fix this:
Step 1: Locate your plugin's files
Open Sublime Text, go to Preferences > Browse Packages, and find the folder for the LaTeX helper plugin you're using. Inside, you'll find .py files that handle the environment generation logic.
Step 2: Modify the environment generation code
Look for a function that's inserting the eqnarray* environment—it might look something like this:
def insert_eqnarray_environment(self): self.view.run_command('insert_snippet', { 'contents': r'\begin{eqnarray*}\n\t${1:your_equation_here}\n\end{eqnarray*}' })
Rewrite this to generate the align* environment instead:
def insert_align_environment(self): self.view.run_command('insert_snippet', { 'contents': r'\begin{align*}\n\t${1:your_equation_here}\n\end{align*}' })
If the plugin uses keyboard shortcuts to trigger this, head to the plugin's Default.sublime-keymap file and update the command to match your new function name. For example:
{ "keys": ["ctrl+shift+a"], "command": "insert_align_environment" }
Step 3: Fix automatic parameter-triggered wrapping
If the plugin is auto-wrapping your equations in eqnarray* when you input specific parameters, find the part of the code that handles this auto-replacement. Look for lines that replace text with eqnarray* tags, and swap them out for align*:
def on_modified(self): # Example of auto-replacement logic you might find selection = self.view.sel()[0] current_text = self.view.substr(selection) # Check if your trigger condition is met (e.g., specific parameter input) if self.trigger_condition_met(current_text): # Replace eqnarray* with align* updated_text = current_text.replace(r'\begin{eqnarray*}', r'\begin{align*}') updated_text = updated_text.replace(r'\end{eqnarray*}', r'\end{align*}') self.view.run_command('replace', {'text': updated_text})
Quick reminder
Don't forget to add \usepackage{amsmath} to the preamble of your LaTeX document—this package is required for the align* environment to work properly.
内容的提问来源于stack exchange,提问作者rsc05

