diff --git a/CLAUDE.md b/CLAUDE.md index 25d9e26215..465d2a0e14 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -32,6 +32,10 @@ 2. 构建方式:`xmake b xxx_test` 3. 运行方式:`xmake r xxx_test` +## 构建命令 + +主项目构建:`xmake b stem` + ## 工作流程 1. 基于主分支创建新分支 diff --git a/TeXmacs/packages/standard/std-latex-base.ts b/TeXmacs/packages/standard/std-latex-base.ts index aa9d06e062..38820a1721 100644 --- a/TeXmacs/packages/standard/std-latex-base.ts +++ b/TeXmacs/packages/standard/std-latex-base.ts @@ -45,14 +45,6 @@ ||||>>>> > - - preview - > - - | - preview>>>>|>>>>>>>> - <\active*> <\src-comment> Footnotes. diff --git a/TeXmacs/plugins/latex/progs/binary/pdflatex.scm b/TeXmacs/plugins/latex/progs/binary/pdflatex.scm deleted file mode 100644 index 2ee3297418..0000000000 --- a/TeXmacs/plugins/latex/progs/binary/pdflatex.scm +++ /dev/null @@ -1,35 +0,0 @@ - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; MODULE : pdflatex.scm -;; DESCRIPTION : pdflatex Binary plugin -;; COPYRIGHT : (C) 2024 Darcy Shen -;; -;; This software falls under the GNU general public license version 3 or later. -;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE -;; in the root directory or . -;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(texmacs-module (binary pdflatex) - (:use (binary common))) - -(define (pdflatex-binary-candidates) - (cond ((os-macos?) - (list "/opt/homebrew/bin/pdflatex" - "/usr/local/bin/pdflatex")) - ((os-win32?) - (list )) - (else - (list "/usr/bin/pdflatex")))) - -(tm-define (find-binary-pdflatex) - (:synopsis "Find the url to the pdflatex binary, return (url-none) if not found") - (find-binary (pdflatex-binary-candidates) "pdflatex")) - -(tm-define (has-binary-pdflatex?) - (not (url-none? (find-binary-pdflatex)))) - -(tm-define (version-binary-pdflatex) - (version-binary (find-binary-pdflatex))) - diff --git a/TeXmacs/progs/texmacs/texmacs/tm-server.scm b/TeXmacs/progs/texmacs/texmacs/tm-server.scm index b6dd5330dd..54e60e705a 100644 --- a/TeXmacs/progs/texmacs/texmacs/tm-server.scm +++ b/TeXmacs/progs/texmacs/texmacs/tm-server.scm @@ -55,10 +55,6 @@ ((== val "prompt on scripts") (set-script-status 1)) ((== val "accept all scripts") (set-script-status 2)))) -(define (notify-latex-command var val) - (if (use-plugin-tex?) - (set-latex-command val))) - (define (notify-bibtex-command var val) (if (use-plugin-bibtex?) (set-bibtex-command val))) @@ -113,7 +109,6 @@ ("manual zealous invisible correct" "off" (lambda args (noop))) ("manual homoglyph correct" "on" (lambda args (noop))) ("security" "prompt on scripts" notify-security) - ("latex command" "pdflatex" notify-latex-command) ("bibtex command" "bibtex" notify-bibtex-command) ("scripting language" "none" notify-scripting-language) ("speech" "off" noop) diff --git a/devel/0130.md b/devel/0130.md index a6641253ba..66a5f4059b 100644 --- a/devel/0130.md +++ b/devel/0130.md @@ -8,6 +8,17 @@ - `TeXmacs/progs/convert/latex/tmtex-widgets.scm` - `TeXmacs/plugins/latex/progs/convert/latex/tmtex-widgets.scm` - `TeXmacs/progs/init-research.scm` +- `src/Plugins/Tex/latex_recover.cpp` +- `src/Plugins/Tex/tex.hpp` +- `src/Scheme/Plugins/glue_tex.lua` +- `src/Plugins/LaTeX_Preview/latex_preview.cpp` +- `src/Plugins/LaTeX_Preview/latex_preview.hpp` +- `src/Plugins/Tex/fromtex.cpp` +- `src/Plugins/Tex/fromtex_post.cpp` +- `src/Scheme/Plugins/init_glue_plugins.cpp` +- `src/Data/Convert/Verbatim/verbatim.cpp` +- `src/System/config.h.xmake` +- `xmake.lua` ## 3 如何测试 @@ -52,8 +63,34 @@ Mogan STEM 的目标用户大多不安装本地 TeX Live,而是使用 Overleaf 因此,这三个菜单项均应移除。 -### 7.2 修改步骤 +此外,scheme 入口移除后,对应的 C++ glue 实现也应一并清理,避免留下无调用者的死代码。 + +### 7.2 修改步骤(Scheme 层) 1. **移除菜单入口**:在 `TeXmacs/progs/texmacs/menus/tools-menu.scm` 中,移除条件显示的 `LaTeX` 子菜单(`(-> "LaTeX" (link tmtex-menu))`)。 2. **移除函数和菜单绑定**:在 `TeXmacs/progs/convert/latex/tmtex-widgets.scm` 和 `TeXmacs/plugins/latex/progs/convert/latex/tmtex-widgets.scm` 中,移除 `latex-export`、`latex-run`、`latex-preview` 三个函数,以及 `tmtex-menu` 的 `menu-bind`。 3. **移除懒加载引用**:在 `TeXmacs/progs/init-research.scm` 中,移除 `tmtex-menu` 的 `lazy-menu` 引用。 + +### 7.3 修改步骤(C++ 层) + +#### 7.3.1 移除 `try_latex_export` 及辅助函数 + +`latex-run` 被移除后,`try-latex-export` 在 scheme 中不再有调用者。其 C++ 实现 `try_latex_export` 及所有辅助函数(`number_latex_errors`、`get_latex_errors`、`latex_error_*`、`texmacs_error_find`、`get_line_number`、`get_column_number`)均变为死代码。 + +- **移除实现**:在 `src/Plugins/Tex/latex_recover.cpp` 中移除上述所有函数。 +- **移除声明**:在 `src/Plugins/Tex/tex.hpp` 中移除对应的函数声明。 +- **移除 glue**:在 `src/Scheme/Plugins/glue_tex.lua` 中移除 `try-latex-export`、`number-latex-errors`、`get-line-number`、`get-column-number` 的 glue 定义。`build/glue/glue_tex.cpp` 为自动生成文件,在重新构建时会同步更新。 + +#### 7.3.2 移除 `LaTeX_Preview` 插件 + +`latex-preview` 的设计意图是调用外部 `pdflatex` 生成 PDF。Mogan STEM 不依赖本地 LaTeX 命令行,因此 `LaTeX_Preview` 插件(在导入 LaTeX 时用于将公式渲染为图片,同样依赖 `pdflatex` 和 `gs`)也应一并移除。 + +- **删除插件源码**:删除 `src/Plugins/LaTeX_Preview/latex_preview.cpp` 和 `latex_preview.hpp`。 +- **修改构建系统**: + - 在 `xmake.lua` 中移除 `src/Plugins/LaTeX_Preview/**.cpp` 的编译规则。 + - 在 `src/System/config.h.xmake` 中移除 `USE_PLUGIN_LATEX_PREVIEW` 宏定义。 +- **移除引用**: + - 在 `src/Scheme/Plugins/init_glue_plugins.cpp` 中移除 `#include "LaTeX_Preview/latex_preview.hpp"`。 + - 在 `src/Data/Convert/Verbatim/verbatim.cpp` 中移除 `latex_preview` 的类型检查。 + - 在 `src/Plugins/Tex/fromtex.cpp` 中移除 `#include "LaTeX_Preview/latex_preview.hpp"`,并移除 `find_latex_previews`、`substitute_latex_previews`、`merge_environment_previews`、`count_unbalanced_preview` 等内部辅助函数。将 `latex_fallback_on_pictures` 改为空实现(直接 `return t;`)。 + - 在 `src/Plugins/Tex/fromtex_post.cpp` 中移除 `#include "LaTeX_Preview/latex_preview.hpp"` 和 `latex_fallback_on_pictures` 的前置声明。 diff --git a/src/Data/Convert/Verbatim/verbatim.cpp b/src/Data/Convert/Verbatim/verbatim.cpp index 0aef24336a..167f4de815 100644 --- a/src/Data/Convert/Verbatim/verbatim.cpp +++ b/src/Data/Convert/Verbatim/verbatim.cpp @@ -384,6 +384,5 @@ is_verbatim (tree t) { is_compound (t, "scm-code") || is_compound (t, "shell-code") || is_compound (t, "code") || is_compound (t, "verbatim") || is_compound (t, "scilab-code") || is_compound (t, "scala-code") || - is_compound (t, "java-code") || is_compound (t, "latex_preview") || - is_compound (t, "picture-mixed"); + is_compound (t, "java-code") || is_compound (t, "picture-mixed"); } diff --git a/src/Plugins/LaTeX_Preview/latex_preview.cpp b/src/Plugins/LaTeX_Preview/latex_preview.cpp deleted file mode 100644 index afdff4b0a3..0000000000 --- a/src/Plugins/LaTeX_Preview/latex_preview.cpp +++ /dev/null @@ -1,260 +0,0 @@ - -/****************************************************************************** - * MODULE : latex_preview.cpp - * DESCRIPTION: generating pictures using LaTeX with preview package - * COPYRIGHT : (C) 2013 François Poulain, Joris van der Hoeven - ******************************************************************************* - * This software falls under the GNU general public license version 3 or later. - * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE - * in the root directory or . - ******************************************************************************/ - -#include "LaTeX_Preview/latex_preview.hpp" -#include "Ghostscript/gs_utilities.hpp" -#include "Tex/convert_tex.hpp" -#include "Tex/tex.hpp" -#include "analyze.hpp" -#include "file.hpp" -#include "lolly/system/subprocess.hpp" -#include "sys_utils.hpp" -#include "tm_file.hpp" -#include "tree_helper.hpp" - -using namespace moebius; - -static inline void -dbg (string s) { - if (DEBUG_CONVERT) debug_convert << s << LF; -} - -static string latex_command= "pdflatex"; - -void -set_latex_command (string cmd) { - latex_command= cmd; -} - -#ifndef USE_PLUGIN_LATEX_PREVIEW -array -latex_preview (string s, tree t) { - dbg ("LaTeX preview disabled in WASM"); - return array (); -} -#else - -bool -latex_present () { - return exists_in_path (latex_command); -} - -array -search_latex_previews (tree t) { - array r; - if (is_atomic (t)) - ; - else if (is_tuple (t, "\\def") || is_tuple (t, "\\def*") || - is_tuple (t, "\\def**") || is_tuple (t, "\\newenvironment**") || - is_tuple (t, "\\newenvironment") || - is_tuple (t, "\\newenvironment*")) - ; - else if (is_tuple (t, "\\latex_preview", 2)) r << as_string (t[1]); - else { - int i, n= N (t); - for (i= 0; i < n; i++) - r << search_latex_previews (t[i]); - } - return r; -} - -void -latex_clean_tmp_directory (url u) { - bool flag = false; - array content= read_directory (u, flag); - for (int i= 0; i < N (content); i++) - if (content[i] != "." && content[i] != "..") remove (u * content[i]); - rmdir (u); -} - -string -latex_remove_fmt (string s) { - int i= 0, start= 0, n= N (s); - while (i < n) { - if (test (s, 0, "%&") || (i > 0 && test (s, i, "\n%&"))) { - start = i++; - bool cut= false; - while (i < n && s[i] != '\n') { - if (test (s, i, "tex")) cut= true; - i++; - } - if (cut) { - s= s (0, start) * '\n' * s (i + 1, n); - n= N (s); - } - } - else if (test (s, i, "\\usepackage") || test (s, i, "\\begin")) break; - i++; - } - return s; -} - -void -latex_install_preview (string s, tree t, url wdir, bool dvips) { - s = latex_remove_fmt (s); - int i = 0; - array macros= search_latex_previews (t); - hashmap done (false); - string preview= "%%%%%%%%%%%%%% ADDED BY TEXMACS %%%%%%%%%%%%%%%%%%\n"; - if (!dvips) preview << "\\usepackage[active,tightpage,delayed]{preview}\n"; - else - preview - << "\\usepackage[active,tightpage,delayed,psfixbb,dvips]{preview}\n"; - - for (i= 0; i < N (macros); i++) { - if (macros[i] == "") continue; - if (done[macros[i]]) continue; - if (test (macros[i], 0, "end-")) continue; - int arity = latex_arity (macros[i]); - bool option= (arity < 0); - string arity_code; - if (option) { - arity_code << "[]"; - arity= -arity; - } - while (arity-- > 0) - arity_code << "{}"; - string name= "\\" * macros[i]; - string cmd = "\\PreviewMacro"; - if (test (name, 0, "\\begin-")) { - name= name (7, N (name)); - cmd = "\\PreviewEnvironment"; - } - preview << cmd << "[{" * arity_code * "}]{" * name * "}\n"; - done (macros[i])= true; - } - preview << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; - - i= latex_search_forwards ("\\documentclass", 0, s); - i= latex_search_forwards ("{", i, s); - i= latex_search_forwards ("}", i, s); - i= latex_search_forwards ("\n", i, s); - i++; - s= s (0, i) * preview * s (i, N (s)); - save_string (wdir * "temp.tex", s); -} - -tree -latex_load_image (url image) { -#if defined(USE_PLUGIN_GS) - string s; - tree t (IMAGE, 5); - load_string (image, s, false); - if (s == "") { - dbg ("Could not load " * as_string (image)); - return as_tree (array ()); - } - int width, height; - gs_image_size (image, width, height); - t[0]= tuple (tree (RAW_DATA, s), "eps"); - t[1]= as_string (width) * "pt"; - t[2]= as_string (height) * "pt"; - return (t); -#else - dbg ("latex_load_image failed because ghostscript is not available"); - return array (); -#endif -} - -array -latex_load_preview (url wdir, bool dvips= false) { -#if defined(USE_PLUGIN_GS) - string cmdln= "cd \"" * as_string (wdir) * "\"; "; - if (dvips) { - cmdln << "dvips temp.dvi && " - << gs_prefix () * " -sDEVICE=" * eps_device () * - " -dSAFER -q -dNOPAUSE -dBATCH " - << "-dLanguageLevel=3 -sOutputFile=temp%d.eps temp.ps"; - } - else { - cmdln << gs_prefix () * " -sDEVICE=" * eps_device () * - " -dSAFER -q -dNOPAUSE -dBATCH " - << "-dLanguageLevel=3 -sOutputFile=temp%d.eps temp.pdf"; - } - dbg ("GS command: " * cmdln); - if (lolly::system::call (cmdln)) { - dbg ("Could not extract pictures from LaTeX document"); - return array (); - } - unsigned int cnt = 1; - bool stop= false; - array r; - while (!stop) { - url u= wdir * ("temp" * as_string (cnt) * ".eps"); - if (exists (u)) { - // gs can produce empty pictures, to be ignored - tree tmp= latex_load_image (u); - if (N (tmp) == 5 && (tmp[1] != "0pt" || tmp[2] != "0pt")) r << tmp; - cnt++; - } - else stop= true; - } - return r; -#else - dbg ("latex_load_preview failed because ghostscript is not available"); - return array (); -#endif -} - -array -latex_preview (string s, tree t) { - if (!latex_present () && !exists_in_path ("latex")) { - dbg ("LaTeX preview: " * latex_command * " not found"); - return array (); - } - if (!exists_in_path ("gs")) { - dbg ("LaTeX preview: ghostscript not found"); - return array (); - } - // FIXME: ./Texmacs/Window/tm_frame.cpp:191 seems to crash here if we launch - // system_wait ("LaTeX: compiling document, ", "please wait"); - url wdir= url_temp ("_latex_preview"); - mkdir (wdir); - bool dvips= false; - latex_install_preview (s, t, wdir, dvips); - string document_root= as_string (head (get_file_focus ())); - string cmdln = "cd " * document_root; - cmdln << "; " << latex_command - << " -interaction nonstopmode -halt-on-error -file-line-error " - << " -output-directory \"" << as_string (wdir) << "\" \"" - << as_string (wdir) << "/temp.tex\""; - dbg ("LaTeX command: " * cmdln); - if (lolly::system::call (cmdln)) { - dbg ("Could not compile LaTeX document using " * latex_command); - dbg ("Try to fallback on LaTeX"); - dvips= true; - latex_install_preview (s, t, wdir, dvips); - cmdln= "cd " * document_root; - cmdln << "; latex" - << " -interaction nonstopmode -halt-on-error -file-line-error " - << " -output-directory \"" << as_string (wdir) << "\" \"" - << as_string (wdir) << "/temp.tex\""; - dbg ("LaTeX command: " * cmdln); - if (lolly::system::call (cmdln)) { - dbg ("Could not compile LaTeX document"); - latex_clean_tmp_directory (wdir); - return array (); - } - } - array r = latex_load_preview (wdir, dvips); - int exp= N (search_latex_previews (t)); - if (N (r) != exp) { - string msg; - msg << "Warning: did not found the expected number of pictures:\n" - << " Got " << as_string (N (r)) << " whereas expected " - << as_string (exp) << ".\n LaTeX compilation or picture" - << " importation might have failed"; - dbg (msg); - } - latex_clean_tmp_directory (wdir); - return r; -} -#endif // OS_WASM diff --git a/src/Plugins/LaTeX_Preview/latex_preview.hpp b/src/Plugins/LaTeX_Preview/latex_preview.hpp deleted file mode 100644 index 061b89a93d..0000000000 --- a/src/Plugins/LaTeX_Preview/latex_preview.hpp +++ /dev/null @@ -1,21 +0,0 @@ - -/****************************************************************************** - * MODULE : latex_preview.hpp - * DESCRIPTION: generating pictures using LaTeX with preview package - * COPYRIGHT : (C) 2013 François Poulain, Joris van der Hoeven - ******************************************************************************* - * This software falls under the GNU general public license version 3 or later. - * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE - * in the root directory or . - ******************************************************************************/ - -#ifndef LATEX_PREVIEW_H -#define LATEX_PREVIEW_H - -#include "array.hpp" -#include "tree.hpp" - -array latex_preview (string s, tree t); -void set_latex_command (string cmd); - -#endif // LATEX_PREVIEW_H diff --git a/src/Plugins/Tex/fromtex.cpp b/src/Plugins/Tex/fromtex.cpp index dbf0448e97..79fd515ca2 100644 --- a/src/Plugins/Tex/fromtex.cpp +++ b/src/Plugins/Tex/fromtex.cpp @@ -9,7 +9,6 @@ * in the root directory or . ******************************************************************************/ -#include "LaTeX_Preview/latex_preview.hpp" #include "Tex/convert_tex.hpp" #include "Tex/tex.hpp" #include "cork.hpp" @@ -648,111 +647,13 @@ filter_preamble (tree t) { } /****************************************************************************** - * Import macro as pictures + * Import macro as pictures (no-op: LaTeX_Preview plugin removed) ******************************************************************************/ -bool -find_latex_previews (tree t) { - if (is_atomic (t)) return false; - else if (is_tuple (t, "\\latex_preview", 2)) return true; - else { - int i, n= N (t); - for (i= 0; i < n; i++) - if (find_latex_previews (t[i])) return true; - } - return false; -} - -tree -substitute_latex_previews (tree t, array a, int& i) { - if (N (a) <= i) - ; - else if (is_atomic (t)) - ; - else if (is_tuple (t, "\\latex_preview", 2)) { - t[0]= "\\picture-mixed"; - t[1]= a[i++]; - } - else if (is_tuple (t, "\\def") || is_tuple (t, "\\def*") || - is_tuple (t, "\\def**") || is_tuple (t, "\\newenvironment**") || - is_tuple (t, "\\newenvironment") || - is_tuple (t, "\\newenvironment*")) - ; - else { - int j, n= N (t); - for (j= 0; j < n; j++) - t[j]= substitute_latex_previews (t[j], a, i); - } - return t; -} - -static int -count_unbalanced_preview (tree t) { - if (!is_concat (t)) return 0; - int i, n= N (t), count= 0; - for (i= 0; i < n; i++) { - tree v= t[i]; - if (is_tuple (v, "\\latex_preview", 2) && - starts (as_string (v[1]), "begin-")) - count++; - if (is_tuple (v, "\\latex_preview", 2) && starts (as_string (v[1]), "end-")) - count--; - if (is_concat (v)) count+= count_unbalanced_preview (v); - } - return count; -} - -static tree -merge_environment_previews (tree t) { - if (is_atomic (t)) return t; - else if (is_tuple (t, "\\def") || is_tuple (t, "\\def*") || - is_tuple (t, "\\def**") || is_tuple (t, "\\newenvironment**") || - is_tuple (t, "\\newenvironment") || - is_tuple (t, "\\newenvironment*")) - return t; - int i, n= N (t); - tree r (L (t)); - string name= ""; - tree code; - bool in_env= false; - for (i= 0; i < n; i++) { - tree v= t[i]; - if (!in_env && is_concat (t) && is_tuple (v, "\\latex_preview", 2) && - starts (as_string (v[1]), "begin-")) { - in_env= true; - name = as_string (v[1]); - code = v[2]; - } - if (in_env && is_concat (t) && is_tuple (v, "\\latex_preview", 2) && - starts (as_string (v[1]), "end-")) { - in_env= false; - code = concat (code, v[2]); - r << tuple ("\\latex_preview", name, code); - name= ""; - } - else if (is_concat (t) && count_unbalanced_preview (v) != 0) { - tree tmp (CONCAT); - int j, m= N (v); - for (j= 0; j < m; j++) - tmp << v[j]; - for (j= i + 1; j < n; j++) - tmp << t[j]; - t= tmp; - n= N (t); - i= -1; - } - else if (!in_env) r << merge_environment_previews (v); - } - return r; -} - tree latex_fallback_on_pictures (string s, tree t) { - if (!find_latex_previews (t)) return t; - int i = 0; - t = merge_environment_previews (t); - array a= latex_preview (s, t); - return substitute_latex_previews (t, a, i); + (void) s; + return t; } /****************************************************************************** diff --git a/src/Plugins/Tex/fromtex_post.cpp b/src/Plugins/Tex/fromtex_post.cpp index 44f510e275..3c18efe885 100644 --- a/src/Plugins/Tex/fromtex_post.cpp +++ b/src/Plugins/Tex/fromtex_post.cpp @@ -9,7 +9,6 @@ * in the root directory or . ******************************************************************************/ -#include "LaTeX_Preview/latex_preview.hpp" #include "Tex/convert_tex.hpp" #include "Tex/tex.hpp" #include "converter.hpp" @@ -42,7 +41,6 @@ extern bool textm_natbib; tree kill_space_invaders (tree t); tree set_special_fonts (tree t, string lan); tree filter_preamble (tree t); -tree latex_fallback_on_pictures (string s, tree t); tree parsed_latex_to_tree (tree t); tree latex_command_to_tree (tree t); bool is_var_compound (tree t, string s); @@ -2477,8 +2475,7 @@ latex_document_to_tree (string s, bool as_pic) { command_arity->extend (); command_def->extend (); tree t= parse_latex_document (s, true, as_pic); - if (as_pic) t= latex_fallback_on_pictures (s, t); - r= latex_to_tree (t); + r = latex_to_tree (t); command_type->shorten (); command_arity->shorten (); command_def->shorten (); diff --git a/src/Plugins/Tex/latex_recover.cpp b/src/Plugins/Tex/latex_recover.cpp index 00e7f9b9c3..82ebd82ed7 100644 --- a/src/Plugins/Tex/latex_recover.cpp +++ b/src/Plugins/Tex/latex_recover.cpp @@ -13,64 +13,13 @@ #include "Tex/tex.hpp" #include "analyze.hpp" #include "file.hpp" -#include "iterator.hpp" -#include "lolly/system/subprocess.hpp" -#include "scheme.hpp" #include "sys_utils.hpp" #include "tm_file.hpp" -#include - -using namespace moebius; - -tree latex_expand (tree doc, url name); -bool tracked_tree_to_latex_document (tree, object, string&, string&); -string latex_unmark (string, hashset, hashmap>&); /****************************************************************************** * Getting information out of log files ******************************************************************************/ -int -number_latex_errors (url log) { - string s; - if (load_string (log, s, false)) return -1; - // cout << "Log file" << LF << HRULE << s << HRULE; - return count_occurrences ("\12! ", s) + count_occurrences ("\15! ", s); -} - -tree -get_latex_errors (url log) { - string s; - tree t (TUPLE); - if (load_string (log, s, false)) return t; - int i= 0, n= N (s); - while (i < n) { - while (i < n) { - if (i + 1 < n && s[i] == '!' && s[i + 1] == ' ') - if (i == 0 || s[i - 1] == '\12' || s[i - 1] == '\15') break; - i++; - } - if (i < n) { - int start= i; - while (i < n) { - while (i < n) { - if (i > 0 && s[i - 1] == '\n' && s[i] == '\n') break; - if (i > 0 && s[i - 1] == '\n' && s[i] == '\15' && s[i] == '\n') break; - i++; - } - string ss= s (start, i); - if (occurs ("\12l.", ss) || occurs ("\15l.", ss)) break; - i++; - } - string ss= s (start, i); - ss = replace (ss, "\15\12", "\n"); - ss = replace (ss, "\12\15", "\n"); - t << s (start, i); - } - } - return t; -} - int number_latex_pages (url log) { string s; @@ -84,247 +33,3 @@ number_latex_pages (url log) { pos--; return as_int (s (pos, end)); } - -/****************************************************************************** - * Parsing the error message - ******************************************************************************/ - -static string -first_line (string s) { - int pos= search_forwards ("\n", s); - if (pos < 0) return s; - else return s (0, pos); -} - -static string -other_lines (string s) { - int pos= search_forwards ("\n", s); - if (pos < 0) return ""; - else return s (pos + 1, N (s)); -} - -string -latex_error_head (string s) { - int pos= search_forwards ("\nl.", s); - if (pos < 0) return s; - string ss= s (0, pos); - while (ends (ss, "\n")) - ss= ss (0, N (ss) - 1); - return ss; -} - -string -latex_error_tail (string s) { - int pos= search_forwards ("\nl.", s); - if (pos < 0) return ""; - return s (pos + 1, N (s)); -} - -string -latex_error_message (string s) { - return first_line (s); -} - -void -strip (string& s, string what) { - if (ends (s, what)) s= s (0, N (s) - N (what)); - while (ends (s, "\n") || ends (s, " ")) - s= s (0, N (s) - 1); -} - -string -latex_error_explain (string s) { - string ss= other_lines (latex_error_head (s)); - while (starts (ss, "\n")) - ss= ss (1, N (ss)); - while (ends (ss, "\n") || ends (ss, " ")) - ss= ss (0, N (ss) - 1); - strip (ss, "..."); - strip (ss, "Type H for immediate help."); - return ss; -} - -string -latex_error_position (string s) { - string t = latex_error_tail (s); - string l1= first_line (t); - string l2= first_line (other_lines (t)); - return l1 * "\n" * l2; -} - -string -latex_error_line (string s) { - string t= latex_error_tail (s); - if (!starts (t, "l.")) return "?"; - int pos= search_forwards (" ", t); - if (pos < 0) return "?"; - return t (2, pos); -} - -string -latex_error_extra (string s) { - string t= latex_error_tail (s); - string x= other_lines (other_lines (t)); - while (starts (x, "\n")) - x= x (1, N (x)); - while (ends (x, "\n") || ends (x, " ")) - x= x (0, N (x) - 1); - strip (x, "or to continue without it."); - strip (x, "Type I to replace it with another command,"); - strip (x, "If that doesn't work, type X to quit."); - strip (x, "Try typing to proceed."); - return x; -} - -/****************************************************************************** - * Finding the error in the LaTeX file - ******************************************************************************/ - -static int -find_line (string s, int l) { - int pos= 0, n= N (s); - l--; - while (pos < n && l > 0) { - if (s[pos] == '\n') l--; - pos++; - } - return pos; -} - -int -latex_error_find (string s, string src) { - string ls= latex_error_position (s); - string l1= first_line (ls); - string l2= other_lines (ls); - if (!starts (l1, "l.")) return -1; - if (N (l2) < N (l1)) return -1; - for (int i= 0; i < N (l1); i++) - if (l2[i] != ' ') return -1; - s = l1 * l2 (N (l1), N (l2)); - int offset= search_forwards (" ", s); - if (offset < 0) return -1; - string lnr= s (2, offset); - while (offset < N (s) && s[offset] == ' ') - offset++; - s= s (offset, N (s)); - if (starts (s, "...")) { - offset+= 3; - s= s (3, N (s)); - } - if (ends (s, "...")) s= s (0, N (s) - 3); - if (!is_int (lnr)) return -1; - int pos= find_line (src, as_int (lnr)); - int bef= search_backwards (s, pos, src); - int aft= search_forwards (s, pos, src); - int ind= N (l1) - offset; - if (bef >= 0) bef+= ind; - if (aft >= 0) aft+= ind; - if (bef < 0 && aft < 0) return -1; - if (bef < 0) return aft; - if (aft < 0) return bef; - if (pos - bef < aft - pos) return bef; - else return aft; -} - -int -get_line_number (string s, int pos) { - int l= 1; - pos = min (pos, N (s)); - for (int i= 0; i < pos; i++) - if (s[i] == '\n') l++; - return l; -} - -int -get_column_number (string s, int pos) { - int c= 0; - pos = min (pos, N (s)); - for (int i= 0; i < pos; i++) - if (s[i] == '\n') c= 0; - else c++; - return c; -} - -/****************************************************************************** - * Find the error in the TeXmacs source file - ******************************************************************************/ - -path -texmacs_error_find (string s, string src, hashmap> corr) { - int pos= latex_error_find (s, src); - if (pos < 0) return path (); - while (pos > 0) { - if (corr->contains (pos)) { - array a= corr[pos]; - for (int i= 0; i < N (a); i++) - if (!is_nil (a[i]) && last_item (a[i]) == 0) return path_up (a[i]); - } - pos--; - } - return path (); -} - -/****************************************************************************** - * Export, run LaTeX, and analyze - ******************************************************************************/ - -tree -try_latex_export (tree doc, object opts, url src, url dest) { - string s, ms; - doc= latex_expand (doc, src); - // cout << "Exporting to LaTeX\n"; - if (tracked_tree_to_latex_document (doc, opts, s, ms)) { - // cout << "Failed to export\n"; - // return "Error: could not track LaTeX export"; - cout << "TeXmacs] Failed to track LaTeX export\n"; - ms= s; - } - hashmap> corr; - string us= latex_unmark (ms, hashset (), corr); - if (save_string (dest, us, false)) { - // cout << "Could not save\n"; - return "Error: could not save LaTeX export"; - } - // cout << "Running pdflatex\n"; - string cmd= "cd " * sys_concretize (head (dest)) * - "; pdflatex -interaction=batchmode " * - as_system_string (tail (dest)); - // cout << cmd << LF; - lolly::system::call (cmd); - url log = glue (unglue (dest, N (suffix (dest))), "log"); - tree errs= get_latex_errors (log); - tree r (TUPLE); - r << us; - tree b= extract (doc, "body"); - for (int i= 0; i < N (errs); i++) { - string err= errs[i]->label; - // cout << "------------ Error " << i+1 << LF; - // cout << err << LF; - /* - int pos= latex_error_find (err, us); - if (pos < 0) cout << "Position could not be found\n"; - else { - cout << us (max (pos-50, 0), pos) - << "[*]" - << us (pos, min (pos+50, N(us))) << LF; - } - */ - /* - path p= texmacs_error_find (err, us, corr); - if (is_nil (p) || !has_subtree (b, p)) - cout << "Position could not be found\n"; - else cout << subtree (b, p) << LF; - */ - int pos= latex_error_find (err, us); - path p = texmacs_error_find (err, us, corr); - tree t (TUPLE); - t << tree (err) - << tree ("l." * latex_error_line (err) * " " * latex_error_message (err)) - << tree (latex_error_message (err)) << tree (latex_error_explain (err)) - << tree (latex_error_position (err)) << tree (latex_error_extra (err)); - if (pos >= 0) t << as_tree (pos); - if (!is_nil (p) && has_subtree (b, p)) t << (as_tree (p)); - r << t; - } - return r; -} diff --git a/src/Plugins/Tex/tex.hpp b/src/Plugins/Tex/tex.hpp index 7e9c65364b..d4152fa49d 100644 --- a/src/Plugins/Tex/tex.hpp +++ b/src/Plugins/Tex/tex.hpp @@ -31,11 +31,6 @@ tree tracked_latex_to_texmacs (string s, bool as_pic); string conservative_texmacs_to_latex (tree doc, object opts); string tracked_texmacs_to_latex (tree doc, object opts); tree conservative_latex_to_texmacs (string s, bool as_pic); -int get_line_number (string s, int pos); -int get_column_number (string s, int pos); -tree try_latex_export (tree doc, object opts, url src, url dest); -int number_latex_errors (url log); -tree get_latex_errors (url log); int number_latex_pages (url log); tree postprocess_metadata (tree t); diff --git a/src/Scheme/Plugins/glue_tex.lua b/src/Scheme/Plugins/glue_tex.lua index 076833e207..ab4761793c 100644 --- a/src/Scheme/Plugins/glue_tex.lua +++ b/src/Scheme/Plugins/glue_tex.lua @@ -92,22 +92,6 @@ function main() "bool" } }, - { - scm_name = "set-latex-command", - cpp_name = "set_latex_command", - ret_type = "void", - arg_list = { - "string" - } - }, - { - scm_name = "number-latex-errors", - cpp_name = "number_latex_errors", - ret_type = "int", - arg_list = { - "url" - } - }, { scm_name = "number-latex-pages", cpp_name = "number_latex_pages", @@ -116,35 +100,6 @@ function main() "url" } }, - { - scm_name = "try-latex-export", - cpp_name = "try_latex_export", - ret_type = "tree", - arg_list = { - "content", - "object", - "url", - "url" - } - }, - { - scm_name = "get-line-number", - cpp_name = "get_line_number", - ret_type = "int", - arg_list = { - "string", - "int" - } - }, - { - scm_name = "get-column-number", - cpp_name = "get_column_number", - ret_type = "int", - arg_list = { - "string", - "int" - } - }, } } end diff --git a/src/Scheme/Plugins/init_glue_plugins.cpp b/src/Scheme/Plugins/init_glue_plugins.cpp index 1bd43badad..924c78eb64 100644 --- a/src/Scheme/Plugins/init_glue_plugins.cpp +++ b/src/Scheme/Plugins/init_glue_plugins.cpp @@ -15,8 +15,6 @@ #include "object_l2.hpp" #include "s7_tm.hpp" -#include "LaTeX_Preview/latex_preview.hpp" - #include "Xml/xml.hpp" #include "glue_xml.cpp" diff --git a/src/System/config.h.xmake b/src/System/config.h.xmake index 432d3f08a1..d0adf58fb0 100644 --- a/src/System/config.h.xmake +++ b/src/System/config.h.xmake @@ -58,7 +58,6 @@ ${define NOMINMAX} ${define USE_PLUGIN_PDF} ${define USE_PLUGIN_BIBTEX} -${define USE_PLUGIN_LATEX_PREVIEW} ${define USE_PLUGIN_TEX} ${define USE_PLUGIN_ISPELL} ${define USE_PLUGIN_SPARKLE} diff --git a/xmake.lua b/xmake.lua index 4c458bb3ef..a814c9cea4 100644 --- a/xmake.lua +++ b/xmake.lua @@ -70,7 +70,6 @@ add_configfiles("src/System/config.h.xmake", { USE_ICONV = true, USE_PLUGIN_GS = true, USE_PLUGIN_BIBTEX = true, - USE_PLUGIN_LATEX_PREVIEW = true, USE_PLUGIN_TEX = true, USE_PLUGIN_ISPELL = true, USE_PLUGIN_PDF = true, @@ -672,7 +671,6 @@ target("libmogan") do USE_ICONV = true, USE_PLUGIN_GS = true, USE_PLUGIN_BIBTEX = true, - USE_PLUGIN_LATEX_PREVIEW = true, USE_PLUGIN_TEX = true, USE_PLUGIN_ISPELL = true, USE_PLUGIN_PDF = true, @@ -809,7 +807,6 @@ target("libmogan") do "src/Plugins/Ghostscript/**.cpp", "src/Plugins/Ispell/**.cpp", "src/Plugins/Metafont/**.cpp", - "src/Plugins/LaTeX_Preview/**.cpp", "src/Plugins/Openssl/**.cpp", "src/Plugins/Tex/**.cpp", "src/Plugins/Xml/**.cpp",