Skip to content

Commit

Permalink
Optionally close LaTeX input cells immediately on running them (defau…
Browse files Browse the repository at this point in the history
…lt true).
  • Loading branch information
Kasper Peeters committed Nov 9, 2024
1 parent fc27979 commit 005ad10
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client_server/DocumentThread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions client_server/DocumentThread.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions frontend/gtkmm/NotebookWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) );
Expand Down Expand Up @@ -413,6 +416,12 @@ NotebookWindow::NotebookWindow(Cadabra *c, bool ro)
" <attribute name='action'>cdb.EditIgnoreCellOnImport</attribute>"
" </item>"
" </section>"
" <section>"
" <item>"
" <attribute name='label'>Auto-close LaTeX cells</attribute>"
" <attribute name='action'>cdb.AutoCloseLaTeX</attribute>"
" </item>"
" </section>"
" </submenu>"
" <submenu>"
" <attribute name='label'>View</attribute>"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<Glib::Variant<bool>>(state_variant).get();

if(prefs.auto_close_latex == !state) return;

prefs.auto_close_latex = !state;
action_auto_close_latex->set_state(Glib::Variant<bool>::create(prefs.auto_close_latex));
prefs.save();
}

void NotebookWindow::on_prefs_font_size(int num)
{
if(prefs.font_step==num) return;
Expand Down
2 changes: 2 additions & 0 deletions frontend/gtkmm/NotebookWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -323,6 +324,7 @@ namespace cadabra {
// enable/disable them at runtime.
Glib::RefPtr<Gio::SimpleAction> 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.
Expand Down
6 changes: 6 additions & 0 deletions web2/cadabra2/source/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ <h1>Change log</h1>
<a name="devel"></a>
<h3>github devel branch (2.5.9)</h3>
<ul>
<li>Add caching to the processing of substitution rules (Daniel).</li>
<li>Fixes for inline execution of Python functions in maths expressions.</li>
<li>Do not gobble normal output when an error occurs notebook execution.</li>
<li>Fix inconsistent behaviour and crashes with split-view mode.</li>
<li>Fix display of LaTeXForm properties.</li>
<li>Documentation updates.</li>
</ul>

<a name="2.5.8"></a>
Expand Down

0 comments on commit 005ad10

Please sign in to comment.