diff --git a/.eslintrc.json b/.eslintrc.json
index 15d0a84..3599e84 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -21,6 +21,9 @@
"error",
"always"
],
+ "no-useless-escape": [
+ "off"
+ ],
"no-unused-vars": [
"warn",
{ "vars": "all", "args": "after-used", "ignoreRestSiblings": false }
diff --git a/index.html b/index.html
index 3ca63a4..d81f3cb 100644
--- a/index.html
+++ b/index.html
@@ -13,7 +13,7 @@
-
+
@@ -86,8 +86,9 @@ Header
-
-
+
+
+
diff --git a/scripts/consts.js b/scripts/consts.js
index 8e37856..3edcb6a 100644
--- a/scripts/consts.js
+++ b/scripts/consts.js
@@ -195,4 +195,7 @@ export const PLUS = '\u207A';
export const SIGMA = '\u03A3';
/** @constant {string} EMPTY_SET - empty set symbol for regular expressions */
-export const EMPTY_SET = '\u2205';
\ No newline at end of file
+export const EMPTY_SET = '\u2205';
+
+/** @constant {float} LATEX_ANGLE_SCALE - used to scale angels for curved edges in tikzpicture*/
+export const LATEX_ANGLE_SCALE = 8;
diff --git a/scripts/index.js b/scripts/index.js
index dfb1133..8658fdd 100644
--- a/scripts/index.js
+++ b/scripts/index.js
@@ -11,6 +11,7 @@ import * as permalink from './permalink.js';
import * as util from './util.js';
import * as ui_setup from './ui_setup.js';
import * as regex from './regex.js';
+import * as latex from './latex.js';
// if not in browser, don't run
if (typeof document !== 'undefined') {
@@ -389,6 +390,18 @@ function bind_permalink() {
window.addEventListener('hashchange', hash_change_handler);
}
+/** button to generate latex text */
+function bind_latex() {
+ const latex_button = document.getElementById('latex');
+ latex_button.addEventListener('click', () => {
+ const select = document.getElementById('select_machine');
+ const latex_str = latex.serialize(select.value, graph);
+ navigator.clipboard.writeText(latex_str)
+ .then(() => alert('Latex text copied to clipboard'));
+ });
+ return;
+}
+
/** change cursor style when hovering over certain elements */
function bind_mousemove() {
const canvas = drawing.get_canvas();
@@ -405,10 +418,14 @@ function bind_mousemove() {
/** bind context menu for side nav bar and secondary side navbar */
function bind_context_menu_navbar(){
- const navbar = document.querySelector('.nav')
- const secondBar = document.querySelector('#secondbar')
- navbar.addEventListener('click', () => {menus.remove_context_menu()})
- secondBar.addEventListener('click', () => {menus.remove_context_menu()})
+ const navbar = document.querySelector('.nav');
+ const secondBar = document.querySelector('#secondbar');
+ navbar.addEventListener('click', () => {
+ menus.remove_context_menu();
+ });
+ secondBar.addEventListener('click', () => {
+ menus.remove_context_menu();
+ });
/*
for(var btns of navbar){
btns.addEventListener('click', () => {remove_context_menu()})
@@ -422,7 +439,7 @@ function bind_regex() {
const convert_to_nfa_btn = document.getElementById('convert_to_nfa');
convert_to_nfa_btn.addEventListener('click', () => {
console.log(document.getElementById('regex_string').value);
- let inputString = document.getElementById('regex_string').value
+ let inputString = document.getElementById('regex_string').value;
inputString = inputString.replace(/\s/g, '');
if (regex.isValidRegex(inputString)) {
graph = regex.process_string(inputString);
@@ -431,14 +448,14 @@ function bind_regex() {
drawing.draw(graph);
// hist.push_history(graph); NEED TO IMPLEMENT HISTORY BEFORE UNCOMMENTING
} else {
- alert("Invalid regular expression.")
+ alert('Invalid regular expression.');
}
});
const input_field = document.getElementById('regex_string');
input_field.addEventListener('keypress', (e) => {
- if (e.key === "Enter") {
+ if (e.key === 'Enter') {
console.log(document.getElementById('regex_string').value);
- let inputString = document.getElementById('regex_string').value
+ let inputString = document.getElementById('regex_string').value;
inputString = inputString.replace(/\s/g, '');
if (regex.isValidRegex(inputString)) {
graph = regex.process_string(inputString);
@@ -447,10 +464,10 @@ function bind_regex() {
drawing.draw(graph);
// hist.push_history(graph); NEED TO IMPLEMENT HISTORY BEFORE UNCOMMENTING
} else {
- alert("Invalid regular expression.")
+ alert('Invalid regular expression.');
}
}
- })
+ });
}
/** run after all the contents are loaded to hook up callbacks */
@@ -466,6 +483,7 @@ function init() {
bind_scroll();
bind_dd();
bind_permalink();
+ bind_latex();
bind_mousemove();
ui_setup.bind_plus_minus();
ui_setup.add_input_bar(); // called so one input bar appears on opening of homepage
diff --git a/scripts/latex.js b/scripts/latex.js
new file mode 100644
index 0000000..6cf5067
--- /dev/null
+++ b/scripts/latex.js
@@ -0,0 +1,190 @@
+/** @module latex */
+
+// -------------------------------------------------------------
+// @author Meruzhan Sargsyan
+//
+// A module used to export the graph as text used in tikzpicture
+// for easily exporting graphs into latex files
+// -------------------------------------------------------------
+
+//----------------------------------------------
+// Testing Notes:
+// - clipboard only available in secure contexts
+//----------------------------------------------
+
+//----------------------------------------------
+// Current TODO:
+// 1. Self loops only go above
+// 2. Horizontally bend angles have label on the left
+// 3. Fix more complicated state names
+// 4. Overlapping labels for self loops
+//----------------------------------------------
+
+import * as consts from './consts.js';
+import * as linalg from './linalg.js';
+
+let debug = false; // change this to enable/disable logging
+
+/**
+ * compresses graph to tikz space
+ * @param {String} type - type of graph (DFA, NFA, ...)
+ * @param {Array