Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions TeXmacs/plugins/lang/dic/en_US/zh_CN.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@
("Insert the recognized LaTeX code into the document" "仅将识别后的LaTeX代码插入文档")
("Insert the image and the recognized LaTeX code into the document" "将图片与识别后的LaTeX代码插入文档")
("Insert only the picture into the document" "仅将图片插入文档")
("Inserting bibliography in %1" "在 %1 中插入参考文献")
("insertion" "嵌入")
("inside mathematics" "在数学模式中")
("interactive command" "")
Expand Down Expand Up @@ -1438,12 +1439,14 @@
("mode dependent icons" "模式工具栏")
("mode" "模式")
("modifier" "")
("Modifying bibliography for %1" "在 %1 中修改参考文献")
("modify cell alignment" "改变单元格对齐")
("modify cell border" "")
("modify cell padding" "")
("modify cell size" "改变单元格大小")
("modify table border" "")
("modify table padding" "")
("modify" "修改")
("mogan" "墨干")
("mongolian" "")
("month" "月")
Expand Down
4 changes: 3 additions & 1 deletion TeXmacs/plugins/latex/progs/bibtex/bib-complete.scm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
(with l (select (buffer-tree) '(:* bibliography))
(if (nnull? l)
(ahash-set! bib-styles-cache u (tm->string (tree-ref (car l) 1)))
"tm-plain")))))
(if (context-has? "bib-style")
(get-env "bib-style")
"tm-gbt7714-2015"))))))

(tm-define (citekey-list u s)
(:synopsis "Completions for @s in the bibtex file @u as a list")
Expand Down
136 changes: 95 additions & 41 deletions TeXmacs/plugins/latex/progs/bibtex/bib-widgets.scm
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MODULE : bib-widgets.scm
;; DESCRIPTION : Widgets for bibliography
;; COPYRIGHT : (C) 2014 Miguel de Benito Delgado
;; COPYRIGHT : (C) 2014 Miguel de Benito Delgado 2026 Yuki Lu
;;
;; 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
Expand All @@ -18,10 +19,11 @@
(:use (bibtex bib-complete) (generic document-edit)))

(define bibwid-url (string->url ""))
(define bibwid-style "tm-plain")
(define bibwid-style "tm-gbt7714-2015")
(define bibwid-use-relative? #t)
(define bibwid-update-buffer? #t)
(define bibwid-buffer (string->url ""))
(define-public bib-style-cache (make-ahash-table))

(define (bibwid-set-url u)
(cond ((and (== bibwid-use-relative? #t) (url-rooted? u))
Expand All @@ -32,6 +34,8 @@

(define (bibwid-set-style answer)
(set! bibwid-style answer)
(ahash-set! bib-style-cache bibwid-buffer answer)
(refresh-now "bibwid-style-selection")
(refresh-now "bibwid-preview"))

(define (bibwid-output-content t style)
Expand All @@ -43,15 +47,19 @@
(mini-paragraph "480px" ,(bib-process "bib" style (tree->stree t))))))

(define (bibwid-output)
(with style (if (== "tm-" (string-take bibwid-style 3))
(with style (if (and (>= (string-length bibwid-style) 3)
(== "tm-" (string-take bibwid-style 3)))
(string-drop bibwid-style 3)
bibwid-style)
(eval `(use-modules (bibtex ,(string->symbol style))))
(catch #t
(lambda ()
(eval `(use-modules (bibtex ,(string->symbol style)))))
(lambda args #f))
(with u (if (and bibwid-use-relative? (not (url-rooted? bibwid-url)))
(url-append (url-head bibwid-buffer) bibwid-url)
bibwid-url)
(with t (if (url-exists? u)
(parse-bib (string-load u))
(with t (if (url-exists? u)
(parse-bib (string-load u))
(tree ""))
(stree->tree (bibwid-output-content t style))))))

Expand All @@ -70,56 +78,99 @@
(with t (car l)
(tree-set! t 1 bibwid-style)
(tree-set! t 2 (url->string bibwid-url))
(ahash-set! bib-style-cache bibwid-buffer bibwid-style)
(if bibwid-update-buffer? (update-document "bibliography")))))))

(define (bibwid-set-filename u)
(bibwid-set-url u)
(refresh-now "bibwid-file-input")
(refresh-now "bibwid-preview"))

(define (valid-bib-file? url-str)
"Check if a URL string points to a valid BibTeX file."
(let* ((url (if (string? url-str) (string->url url-str) url-str))
(ext (url-suffix url)))
(and (url-exists? url)
(string? ext)
(or (string=? ext "bib")
(string=? ext "tmbib")
(string=? ext "bibtex")))))

(define (bib-standard-styles-with-descriptions)
"Return BibTeX styles with descriptions."
(list
(list "tm-plain" "Plain TeXmacs style - simple alphabetical ordering")
(list "tm-abbrv" "Abbreviated TeXmacs style - abbreviated author names")
(list "tm-abstract" "Abstract TeXmacs style - for abstracts")
(list "tm-acm" "ACM style - for ACM publications")
(list "tm-alpha" "Alpha TeXmacs style - alpha-numeric labels")
(list "tm-elsart-num" "ELSART numbered style - for Elsevier publications")
(list "tm-ieeetr" "IEEE Transactions style")
(list "tm-siam" "SIAM style - for SIAM publications")
(list "tm-unsrt" "Unsorted TeXmacs style - citation order")
(list "tm-gbt7714-2015" "Chinese national standard GB/T 7714-2015 style")))

(define (bib-standard-styles)
"Return list of BibTeX style names."
(map (lambda (s) (if (pair? s) (car s) s))
(bib-standard-styles-with-descriptions)))

(define (bibwid-set-relative val)
(set! bibwid-use-relative? val)
(bibwid-set-filename bibwid-url))

(tm-widget (bibwid-preview)
(resize ("520px" "520px" "9999px") ("100px" "100px" "9999px")
(scrollable
(refreshable "bibwid-preview"
(texmacs-output
(bibwid-output)
'(style "generic"))))))

;; 参考文献弹窗主界面
(tm-widget ((bibliography-widget modify? msg) cmd)
(padded
(hlist >>> (text msg) >>>)
;; 顶部标题区域
(centered
(text (string-append " " msg " ")))
===
(hlist
(text "File:") // //
(refreshable "bibwid-file-input"
(hlist
(input (when (and answer (!= answer (url->string bibwid-url)))
(bibwid-set-url (string->url answer))
(refresh-now "bibwid-preview"))
"file" (list (url->string bibwid-url)) "40em")
// //
(explicit-buttons
("" (choose-file bibwid-set-filename "Choose" "tmbib"))))))
;; 对齐布局区域:包含文件选择和样式选择
(aligned
;; 参考文献文件选择项
(item (text "Bibliography file:")
;; 文件输入区域
(refreshable "bibwid-file-input"
(hlist
(input (lambda (url-str)
(bibwid-set-filename (string->url url-str))
(refresh-now "bibwid-preview"))
"file" (list (url->string bibwid-url)) "40em")
// //
(explicit-buttons
("Browse..." (choose-file bibwid-set-filename "Choose" "tmbib"))))))
===
;; 引用样式选择项
(item (text "Citation style:")
;; 样式选择区域
(refreshable "bibwid-style-selection"
(let* ((styles (bib-standard-styles-with-descriptions))
(style-names (map (lambda (s) (if (pair? s) (car s) s)) styles))
(current-index (or (list-find-index style-names (lambda (x) (string=? x bibwid-style))) 0))
(style-desc (if (and (> (length styles) current-index)
(pair? (list-ref styles current-index)))
(cadr (list-ref styles current-index))
"")))
(vlist
(enum (lambda (style)
(bibwid-set-style style)
(refresh-now "bibwid-preview"))
style-names bibwid-style "200")
===
(when (not (string-null? style-desc))
(padded
(text style-desc))))))))
===
(hlist
;(balloon "Use relative path:" "Select this to use a path relative to the current document. You can use this to be able to move around the folder containing your document and the bibliography.")
(text "Use relative path:") //
(toggle (bibwid-set-relative answer) bibwid-use-relative?)
// //
(text "Update buffer:") //
(toggle (set! bibwid-update-buffer? answer)
bibwid-update-buffer?)
///
(text "Style:") // //
(enum (bibwid-set-style answer) (bib-standard-styles)
bibwid-style "10em"))
=== === ===
(hlist // (dynamic (bibwid-preview)) //)
;; 预览区域:显示参考文献渲染效果
(resize '("520px" "520px" "9999px") '("300px" "300px" "9999px")
(scrollable
(refreshable "bibwid-preview"
(texmacs-output
(bibwid-output)
'(style "generic")))))
===
;; 底部按钮区域
(bottom-buttons >>>
("Cancel" (cmd #f)) // //
(if modify? ("Modify" (cmd #t)))
Expand All @@ -142,6 +193,9 @@
bibwid-modify "Modify bibliography"))
(with msg (replace "Inserting bibliography in %1" name)
(bibwid-set-url (string->url ""))
(set! bibwid-style "tm-plain")
(set! bibwid-style (if (context-has? "bib-style")
(get-env "bib-style")
(let ((cached (ahash-ref bib-style-cache bibwid-buffer)))
(if cached cached "tm-gbt7714-2015"))))
(dialogue-window (bibliography-widget #f msg)
bibwid-insert "Insert bibliography")))))
16 changes: 0 additions & 16 deletions TeXmacs/progs/text/text-edit.scm
Original file line number Diff line number Diff line change
Expand Up @@ -542,22 +542,6 @@
(n (if (== (url-suffix r) "bib") (url-unglue r 4) r)))
(url->string n))))

(tm-define (make-bib file-name)
(:argument file-name "Bibliography file")
(let* ((name (normalized-bib-name file-name))
(aux (if (context-has? "bib-prefix") (get-env "bib-prefix") "bib"))
(style (if (context-has? "bib-style") (get-env "bib-style") "tm-gbt7714-2015")))
(if (not (make-return-after))
(insert-go-to `(bibliography ,aux ,style ,name (document ""))
'(3 0 0)))))

(tm-define (make-database-bib)
(with aux (if (context-has? "bib-prefix") (get-env "bib-prefix") "bib")
(with style (if (context-has? "bib-style") (get-env "bib-style") "tm-gbt7714-2015")
(if (not (make-return-after))
(insert-go-to `(bibliography ,aux ,style "" (document ""))
'(3 0 0))))))

(tm-define (automatic-section-context? t)
(tree-in? t (automatic-section-tag-list)))

Expand Down
8 changes: 1 addition & 7 deletions TeXmacs/progs/text/text-menu.scm
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,7 @@

(menu-bind automatic-menu
("Table of contents" (make-aux "table-of-contents" "toc-prefix" "toc"))
(assuming (get-boolean-preference "gui:new bibliography dialogue")
("Bibliography" (open-bibliography-inserter)))
(assuming (not (get-boolean-preference "gui:new bibliography dialogue"))
(if (with-database-tool?)
("Bibliography" (make-database-bib)))
(if (not (with-database-tool?))
("Bibliography" (choose-file make-bib "Bibliography file" "tmbib"))))
("Bibliography" (open-bibliography-inserter))
("Index" (make-aux "the-index" "index-prefix" "idx"))
("Glossary" (make-aux "the-glossary" "glossary-prefix" "gly"))
;;("List of figures" (make-aux* "the-glossary*" "figure-list-prefix" "figure" "List of figures"))
Expand Down