From 005ad1052bf15e4722f7221b115f3ed8a0cda895 Mon Sep 17 00:00:00 2001 From: Kasper Peeters Date: Sat, 9 Nov 2024 21:26:19 +0000 Subject: [PATCH] Optionally close LaTeX input cells immediately on running them (default true). --- client_server/DocumentThread.cc | 2 ++ client_server/DocumentThread.hh | 1 + frontend/gtkmm/NotebookWindow.cc | 26 ++++++++++++++++++++++++++ frontend/gtkmm/NotebookWindow.hh | 2 ++ web2/cadabra2/source/changelog.html | 6 ++++++ 5 files changed, 37 insertions(+) diff --git a/client_server/DocumentThread.cc b/client_server/DocumentThread.cc index 033e4e5bbb..a6e171b0ad 100644 --- a/client_server/DocumentThread.cc +++ b/client_server/DocumentThread.cc @@ -281,6 +281,7 @@ DocumentThread::Prefs::Prefs(bool use_defaults) move_into_new_cell = data.value("move_into_new_cell", false); tab_completion = data.value("tab_completion", true); microtex = data.value("microtex", true); + auto_close_latex = data.value("auto_close_latex", true); // Force microtex when this is an AppImage. const char *appdir = getenv("APPDIR"); @@ -332,6 +333,7 @@ void DocumentThread::Prefs::save() data["move_into_new_cell"] = move_into_new_cell; data["tab_completion"] = tab_completion; data["microtex"] = microtex; + data["auto_close_latex"] = auto_close_latex; for (const auto& lang : colours) { for (const auto& kw : lang.second) data["colours"][lang.first][kw.first] = kw.second; diff --git a/client_server/DocumentThread.hh b/client_server/DocumentThread.hh index 12c45f76fa..391c0dac4c 100644 --- a/client_server/DocumentThread.hh +++ b/client_server/DocumentThread.hh @@ -117,6 +117,7 @@ namespace cadabra { bool move_into_new_cell; bool tab_completion; bool microtex; + bool auto_close_latex; private: nlohmann::json data; std::string config_path; diff --git a/frontend/gtkmm/NotebookWindow.cc b/frontend/gtkmm/NotebookWindow.cc index cb0109caf3..fae29115eb 100644 --- a/frontend/gtkmm/NotebookWindow.cc +++ b/frontend/gtkmm/NotebookWindow.cc @@ -217,6 +217,9 @@ NotebookWindow::NotebookWindow(Cadabra *c, bool ro) actiongroup->add_action( "EditMakeCellTeX", sigc::mem_fun(*this, &NotebookWindow::on_edit_cell_is_latex) ); actiongroup->add_action( "EditMakeCellPython", sigc::mem_fun(*this, &NotebookWindow::on_edit_cell_is_python) ); actiongroup->add_action( "EditIgnoreCellOnImport",sigc::mem_fun(*this, &NotebookWindow::on_ignore_cell_on_import) ); + action_auto_close_latex = Gio::SimpleAction::create_bool("AutoCloseLaTeX", prefs.auto_close_latex); + action_auto_close_latex->signal_activate().connect( sigc::mem_fun(*this, &NotebookWindow::on_prefs_auto_close_latex) ); + actiongroup->add_action(action_auto_close_latex); // View menu actions. actiongroup->add_action( "ViewSplit", sigc::mem_fun(*this, &NotebookWindow::on_view_split) ); @@ -413,6 +416,12 @@ NotebookWindow::NotebookWindow(Cadabra *c, bool ro) " cdb.EditIgnoreCellOnImport" " " " " + "
" + " " + " Auto-close LaTeX cells" + " cdb.AutoCloseLaTeX" + " " + "
" " " " " " View" @@ -1243,6 +1252,10 @@ void NotebookWindow::add_cell(const DTree& tr, DTree::iterator it, bool visible) newcell.outbox->show_hide_requested.connect( sigc::bind( sigc::mem_fun(this, &NotebookWindow::cell_toggle_visibility), i ) ); + if(prefs.auto_close_latex) { + cell_toggle_visibility(it, i); + } + #if GTKMM_MINOR_VERSION>=10 to_reveal.push_back(&newcell.outbox->rbox); #endif @@ -2548,6 +2561,7 @@ void NotebookWindow::on_help_about() special.push_back("Connor Behan (for various improvements related to index-free algorithms)"); special.push_back("James Allen (for writing much of the factoring code)"); special.push_back("NanoMichael (for the MicroTeX rendering library)"); + special.push_back("Daniel Butter (substitute rule cache and other improvements)"); special.push_back("Software Sustainability Institute"); special.push_back("Institute of Advanced Study (for a Christopherson/Knott fellowship)"); about.add_credit_section("Special thanks", special); @@ -2840,6 +2854,18 @@ void NotebookWindow::compare_git_specific() } } +void NotebookWindow::on_prefs_auto_close_latex(const Glib::VariantBase& vb) + { + auto state_variant = action_auto_close_latex->get_state_variant(); //.get_bool(); + bool state = Glib::VariantBase::cast_dynamic>(state_variant).get(); + + if(prefs.auto_close_latex == !state) return; + + prefs.auto_close_latex = !state; + action_auto_close_latex->set_state(Glib::Variant::create(prefs.auto_close_latex)); + prefs.save(); + } + void NotebookWindow::on_prefs_font_size(int num) { if(prefs.font_step==num) return; diff --git a/frontend/gtkmm/NotebookWindow.hh b/frontend/gtkmm/NotebookWindow.hh index 010e04aca6..04ad087239 100644 --- a/frontend/gtkmm/NotebookWindow.hh +++ b/frontend/gtkmm/NotebookWindow.hh @@ -234,6 +234,7 @@ namespace cadabra { void on_run_stop(); void on_prefs_set_cv(int vis); + void on_prefs_auto_close_latex(const Glib::VariantBase& vb); void on_prefs_font_size(int num); void on_prefs_highlight_syntax(bool on); void on_prefs_microtex(bool on); @@ -323,6 +324,7 @@ namespace cadabra { // enable/disable them at runtime. Glib::RefPtr action_copy, action_undo, action_redo, action_paste, action_view_close, action_fontsize, action_highlight, + action_auto_close_latex, action_stop, action_register, action_console, action_microtex; // Transition animations. diff --git a/web2/cadabra2/source/changelog.html b/web2/cadabra2/source/changelog.html index a905b20d21..ca53d35c11 100644 --- a/web2/cadabra2/source/changelog.html +++ b/web2/cadabra2/source/changelog.html @@ -19,6 +19,12 @@

Change log

github devel branch (2.5.9)

    +
  • Add caching to the processing of substitution rules (Daniel).
  • +
  • Fixes for inline execution of Python functions in maths expressions.
  • +
  • Do not gobble normal output when an error occurs notebook execution.
  • +
  • Fix inconsistent behaviour and crashes with split-view mode.
  • +
  • Fix display of LaTeXForm properties.
  • +
  • Documentation updates.