Update AND detection for chrome extension

This commit is contained in:
Oystein Kristoffer Tveit 2021-05-17 20:32:14 +02:00
parent f7da45a38b
commit ca32d3daff
1 changed files with 28 additions and 5 deletions

View File

@ -89,11 +89,23 @@ const whileFindReplace = (pattern, replacement, text) => {
const convertToPropositionalLogic = latex => { const convertToPropositionalLogic = latex => {
// replace neg
latex = replaceParens(['\\\\overline{', '}'], ['{', '}'], ['\\neg ', ''], latex);
// replace and // 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 // // replace or
latex = latex.replace(/\+/g, ' \\vee '); latex = latex.replace(/\+/g, ' \\vee ');
@ -104,7 +116,18 @@ const convertToPropositionalLogic = latex => {
const convertToSetTheory = latex => { const convertToSetTheory = latex => {
// replace and // 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 // // replace or
latex = latex.replace(/\+/g, ' \\cup '); latex = latex.replace(/\+/g, ' \\cup ');