Update AND detection for chrome extension
This commit is contained in:
parent
f7da45a38b
commit
ca32d3daff
|
@ -89,11 +89,23 @@ const whileFindReplace = (pattern, replacement, text) => {
|
|||
|
||||
const convertToPropositionalLogic = latex => {
|
||||
|
||||
// replace neg
|
||||
latex = replaceParens(['\\\\overline{', '}'], ['{', '}'], ['\\neg ', ''], latex);
|
||||
|
||||
// replace and
|
||||
latex = whileFindReplace(/\b(?!\\cup|\\cap|\\text|\\quad)([A-Z0-9]|\\overline{.+})([A-Z0-9]|\\overline{.+?})(?=[\s\+])/, '($1 \\wedge $2)', latex);
|
||||
const ignoreCommands = ['(?<=[\\s\\+])', '(?=[\\s\\+])']
|
||||
const char = '(?!\\\\text|&\\\\quad&|\\s|\\+)([A-Z0-9]|\\\\overline{.+?})';
|
||||
|
||||
const connectedChars2 = RegExp(`${ignoreCommands[0]}${char.repeat(2)}${ignoreCommands[1]}`)
|
||||
const connectedChars3 = RegExp(`${ignoreCommands[0]}${char.repeat(3)}${ignoreCommands[1]}`)
|
||||
const connectedChars4 = RegExp(`${ignoreCommands[0]}${char.repeat(4)}${ignoreCommands[1]}`)
|
||||
const connectedChars5 = RegExp(`${ignoreCommands[0]}${char.repeat(5)}${ignoreCommands[1]}`)
|
||||
|
||||
latex = whileFindReplace(connectedChars5, '($1 \\wedge $2 \\wedge $3 \\wedge $4 \\wedge $5)', latex);
|
||||
latex = whileFindReplace(connectedChars4, '($1 \\wedge $2 \\wedge $3 \\wedge $4)', latex);
|
||||
latex = whileFindReplace(connectedChars3, '($1 \\wedge $2 \\wedge $3)', latex);
|
||||
latex = whileFindReplace(connectedChars2, '($1 \\wedge $2)', latex);
|
||||
|
||||
// replace neg
|
||||
latex = replaceParens(['\\\\overline{', '}'], ['{', '}'], ['\\neg (', ')'], latex);
|
||||
latex = whileFindReplace(/\\neg \(((?:\\neg )*[A-Za-z])\)/, '\\neg $1', latex);
|
||||
|
||||
// // replace or
|
||||
latex = latex.replace(/\+/g, ' \\vee ');
|
||||
|
@ -104,7 +116,18 @@ const convertToPropositionalLogic = latex => {
|
|||
const convertToSetTheory = latex => {
|
||||
|
||||
// replace and
|
||||
latex = whileFindReplace(/\b(?!\\cup|\\cap|\\text|\\quad)([A-Z0-9]|\\overline{.+})([A-Z0-9]|\\overline{.+?})(?=[\s\+])/, '($1 \\cap $2)', latex);
|
||||
const ignoreCommands = ['(?<=[\\s\\+])', '(?=[\\s\\+])']
|
||||
const char = '(?!\\\\text|&\\\\quad&|\\s|\\+)([A-Z0-9]|\\\\overline{.+?})';
|
||||
|
||||
const connectedChars2 = RegExp(`${ignoreCommands[0]}${char.repeat(2)}${ignoreCommands[1]}`)
|
||||
const connectedChars3 = RegExp(`${ignoreCommands[0]}${char.repeat(3)}${ignoreCommands[1]}`)
|
||||
const connectedChars4 = RegExp(`${ignoreCommands[0]}${char.repeat(4)}${ignoreCommands[1]}`)
|
||||
const connectedChars5 = RegExp(`${ignoreCommands[0]}${char.repeat(5)}${ignoreCommands[1]}`)
|
||||
|
||||
latex = whileFindReplace(connectedChars5, '($1 \\cap $2 \\cap $3 \\cap $4 \\cap $5)', latex);
|
||||
latex = whileFindReplace(connectedChars4, '($1 \\cap $2 \\cap $3 \\cap $4)', latex);
|
||||
latex = whileFindReplace(connectedChars3, '($1 \\cap $2 \\cap $3)', latex);
|
||||
latex = whileFindReplace(connectedChars2, '($1 \\cap $2)', latex);
|
||||
|
||||
// // replace or
|
||||
latex = latex.replace(/\+/g, ' \\cup ');
|
||||
|
|
Loading…
Reference in New Issue