"use strict";(self.webpackChunk_cocalc_static=self.webpackChunk_cocalc_static||[]).push([[4321],{4321:(e,n,t)=>{t.r(n);var i=t(55529),s=t(80643);i.defineOption("autoCloseLatex",!1,(function(e,n,t){if(t&&e.removeKeyMap("autoCloseLatex"),!n)return;const o={name:"autoCloseLatex",Enter:function(e){return function(e){if(e.getOption("disableInput"))return i.Pass;const n=[],t=[];let o=!1,a=0;const l=function(e){n.push("\n");const i={line:e.line+1,ch:0};a+=1,t.push({head:i,anchor:i})};for(const r of e.listSelections()){if(!r.empty())return i.Pass;const u=r.head,f=e.getTokenAt(u);if("stex"!==i.innerMode(e.getMode(),f.state).mode.name){l(u);continue}if("bracket"!==f.type&&"}"!==f.string){l(u);continue}if(e.getTokenAt({line:u.line,ch:u.ch+1}).start!==f.start){l(u);continue}const h=e.getLine(u.line);let d=h.lastIndexOf("\\begin{");if(-1===d){l(u);continue}let g=h.slice(d+"\\begin{".length,u.ch-1);d=g.indexOf("}"),-1!=d&&(g=g.slice(0,d));const p=`\\end{${g}}`,b=e.getRange({line:u.line+1,ch:0},{line:u.line+1e3,ch:0});d=b.indexOf(`\\end{${g}}`);const m=b.indexOf(`\\begin{${g}}`);if(-1!==d&&(-1===m||m>d)){l(u);continue}const x=c(g);n.push(`${x}\n${p}\n`);const k={line:u.line+a+1,ch:x.length};a+=(0,s.splitlines)(n[n.length-1]).length+1,t.push({head:k,anchor:k}),o=!0}if(!o)return i.Pass;e.replaceSelections(n),e.setSelections(t)}(e)}};e.addKeyMap(o)}));var c=function(e){switch(e){case"enumerate":case"itemize":case"list":return"\n\\item First ";case"description":return"\n\\item [label] First  ";case"figure":return"\n% body of the figure\n\\caption{figure title}";default:return"\n"}}}}]);