mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #19512 from overleaf/mj-def-mathjax
[web] Pass def, let, and (re)newenvironment to mathjax GitOrigin-RevId: b79b656024bcaddd1bd96a4b9ed297de2de043e3
This commit is contained in:
parent
291fdd4e30
commit
f4896b2152
4 changed files with 49 additions and 8 deletions
|
@ -616,14 +616,46 @@ export const atomicDecorations = (options: Options) => {
|
||||||
return false // no markup in verbatim content
|
return false // no markup in verbatim content
|
||||||
} else if (
|
} else if (
|
||||||
nodeRef.type.is('NewCommand') ||
|
nodeRef.type.is('NewCommand') ||
|
||||||
nodeRef.type.is('RenewCommand')
|
nodeRef.type.is('RenewCommand') ||
|
||||||
|
nodeRef.type.is('Def')
|
||||||
) {
|
) {
|
||||||
const argumentNode = nodeRef.node.getChild('LiteralArgContent')
|
const nameNode =
|
||||||
if (argumentNode) {
|
nodeRef.node.getChild('LiteralArgContent') ??
|
||||||
const argument = state
|
nodeRef.node.getChild('Csname') ??
|
||||||
.sliceDoc(argumentNode.from, argumentNode.to)
|
nodeRef.node.getChild('CtrlSym')
|
||||||
.trim()
|
if (nameNode) {
|
||||||
if (/^\\\w+/.test(argument)) {
|
const name = state.sliceDoc(nameNode.from, nameNode.to).trim()
|
||||||
|
if (/^\\\w+/.test(name)) {
|
||||||
|
const content = state.sliceDoc(nodeRef.from, nodeRef.to)
|
||||||
|
if (content) {
|
||||||
|
commandDefinitions += `${content}\n`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
|
nodeRef.type.is('RenewEnvironment') ||
|
||||||
|
nodeRef.type.is('NewEnvironment')
|
||||||
|
) {
|
||||||
|
const nameNode = nodeRef.node.getChild('LiteralArgContent')
|
||||||
|
if (nameNode) {
|
||||||
|
const name = state.sliceDoc(nameNode.from, nameNode.to).trim()
|
||||||
|
if (/^\w+/.test(name)) {
|
||||||
|
const content = state.sliceDoc(nodeRef.from, nodeRef.to)
|
||||||
|
if (content) {
|
||||||
|
commandDefinitions += `${content}\n`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (nodeRef.type.is('Let')) {
|
||||||
|
const commandNodes = nodeRef.node.getChildren('Csname')
|
||||||
|
if (commandNodes.length !== 2) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const nameNode = commandNodes[0]
|
||||||
|
if (nameNode) {
|
||||||
|
// We support more flexible names in let (Csname) than in newcommand
|
||||||
|
const name = state.sliceDoc(nameNode.from, nameNode.to).trim()
|
||||||
|
if (name.length > 1 && name.startsWith('\\')) {
|
||||||
const content = state.sliceDoc(nodeRef.from, nodeRef.to)
|
const content = state.sliceDoc(nodeRef.from, nodeRef.to)
|
||||||
if (content) {
|
if (content) {
|
||||||
commandDefinitions += `${content}\n`
|
commandDefinitions += `${content}\n`
|
||||||
|
|
|
@ -129,7 +129,10 @@ export const LaTeXLanguage = LRLanguage.define({
|
||||||
) {
|
) {
|
||||||
types.push('$TextArgument')
|
types.push('$TextArgument')
|
||||||
}
|
}
|
||||||
} else if (type.name.endsWith('Environment')) {
|
} else if (
|
||||||
|
type.name.endsWith('Environment') &&
|
||||||
|
!['NewEnvironment', 'RenewEnvironment'].includes(type.name)
|
||||||
|
) {
|
||||||
types.push('$Environment')
|
types.push('$Environment')
|
||||||
} else if (type.name.endsWith('Brace')) {
|
} else if (type.name.endsWith('Brace')) {
|
||||||
types.push('$Brace')
|
types.push('$Brace')
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
IncludeGraphicsCtrlSeq,
|
IncludeGraphicsCtrlSeq,
|
||||||
CaptionCtrlSeq,
|
CaptionCtrlSeq,
|
||||||
DefCtrlSeq,
|
DefCtrlSeq,
|
||||||
|
LetCtrlSeq,
|
||||||
LeftCtrlSeq,
|
LeftCtrlSeq,
|
||||||
RightCtrlSeq,
|
RightCtrlSeq,
|
||||||
NewCommandCtrlSeq,
|
NewCommandCtrlSeq,
|
||||||
|
@ -293,6 +294,9 @@ KnownCommand<ArgumentType> {
|
||||||
// allow more general Csname argument to \def commands, since other symbols such as '@' are often used in definitions
|
// allow more general Csname argument to \def commands, since other symbols such as '@' are often used in definitions
|
||||||
DefCtrlSeq optionalWhitespace? (Csname | CtrlSym) optionalWhitespace? (MacroParameter | OptionalMacroParameter)* optionalWhitespace? DefinitionArgument
|
DefCtrlSeq optionalWhitespace? (Csname | CtrlSym) optionalWhitespace? (MacroParameter | OptionalMacroParameter)* optionalWhitespace? DefinitionArgument
|
||||||
} |
|
} |
|
||||||
|
Let {
|
||||||
|
LetCtrlSeq Csname optionalWhitespace? "="? optionalWhitespace? Csname
|
||||||
|
} |
|
||||||
Hbox {
|
Hbox {
|
||||||
HboxCtrlSeq optionalWhitespace? TextArgument
|
HboxCtrlSeq optionalWhitespace? TextArgument
|
||||||
} |
|
} |
|
||||||
|
|
|
@ -34,6 +34,7 @@ import {
|
||||||
IncludeGraphicsCtrlSeq,
|
IncludeGraphicsCtrlSeq,
|
||||||
CaptionCtrlSeq,
|
CaptionCtrlSeq,
|
||||||
DefCtrlSeq,
|
DefCtrlSeq,
|
||||||
|
LetCtrlSeq,
|
||||||
LeftCtrlSeq,
|
LeftCtrlSeq,
|
||||||
RightCtrlSeq,
|
RightCtrlSeq,
|
||||||
NewCommandCtrlSeq,
|
NewCommandCtrlSeq,
|
||||||
|
@ -543,6 +544,7 @@ const otherKnowncommands = {
|
||||||
'\\includegraphics': IncludeGraphicsCtrlSeq,
|
'\\includegraphics': IncludeGraphicsCtrlSeq,
|
||||||
'\\caption': CaptionCtrlSeq,
|
'\\caption': CaptionCtrlSeq,
|
||||||
'\\def': DefCtrlSeq,
|
'\\def': DefCtrlSeq,
|
||||||
|
'\\let': LetCtrlSeq,
|
||||||
'\\left': LeftCtrlSeq,
|
'\\left': LeftCtrlSeq,
|
||||||
'\\right': RightCtrlSeq,
|
'\\right': RightCtrlSeq,
|
||||||
'\\newcommand': NewCommandCtrlSeq,
|
'\\newcommand': NewCommandCtrlSeq,
|
||||||
|
|
Loading…
Reference in a new issue