-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[24_15] Add docx converter & test (#1985)
<!-- Thank you for your contribution! --> ## What Added converter for tm, tmu to docx. ## How to test your changes? `xmake r 24_15`
- Loading branch information
Showing
9 changed files
with
200 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; | ||
;; MODULE : docx.scm | ||
;; DESCRIPTION : DOCX data format | ||
;; COPYRIGHT : (C) 2024 ATQlove | ||
;; | ||
;; 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 <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
;; | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
(texmacs-module (data docx) | ||
(:use (binary pandoc) | ||
(texmacs texmacs tm-files) | ||
(network url))) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Function to export TeXmacs document to DOCX using Pandoc | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
(tm-define (export-to-docx input-file output-file) | ||
(:synopsis "Export TeXmacs document to DOCX format using Pandoc") | ||
(let* ((base-dir (url-head input-file)) | ||
(html-file-url (url-glue (url-head output-file) ".html"))) | ||
;; First, export the document to HTML | ||
(tm->html input-file html-file-url) | ||
;; Then, use Pandoc to convert the HTML to DOCX | ||
(if (has-binary-pandoc?) | ||
(let ((cmd (string-append (url->string (find-binary-pandoc)) | ||
" -f html -t docx " | ||
(url->string html-file-url) | ||
" -o " | ||
(url->string output-file)))) | ||
(system cmd) | ||
;; Delete the intermediate HTML file | ||
(system-remove html-file-url)) ;; Expected:$TEXMACS_PATH/tests/tm.html") | ||
(error "Pandoc binary not found")))) | ||
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Helper function to export tm/tmu to HTML | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
(tm-define (tm->html tm-file-url html-file-url) | ||
; Step 1: load the tm file | ||
(display* "load-buffer: " tm-file-url "\n") | ||
(load-buffer tm-file-url) | ||
; it will crash when loading the buffer in beamer style before this pull request | ||
(display* "buffer-loaded: " tm-file-url "\n") | ||
|
||
; Step 2: cleaning for the html file url | ||
(when (url-exists? html-file-url) (system-remove html-file-url)) | ||
|
||
; Step 3: Export the buffer to the html file url | ||
(display* "export buffer to: " html-file-url) | ||
(export-buffer-main (current-buffer) html-file-url "html" ()) | ||
#t) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Converter for exporting TeXmacs files to DOCX | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
(converter texmacs-file docx-file | ||
(:require (has-binary-pandoc?)) | ||
(:function-with-options export-to-docx)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; | ||
;; MODULE : 24_15.scm | ||
;; DESCRIPTION : Test for docx.scm | ||
;; COPYRIGHT : (C) 2024 ATQlove | ||
;; | ||
;; 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 <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
;; | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
(import (srfi srfi-78)) | ||
(use-modules (data docx)) | ||
|
||
(define (tm->docx tm-file-url docx-file-url) | ||
; Step 1: load the tm file | ||
; (display* "load-buffer: " tm-file-url "\n") | ||
(load-buffer tm-file-url) | ||
; (display* "buffer-loaded: " tm-file-url "\n") | ||
|
||
; Step 2: Export the buffer to the docx file url | ||
; (display* "export buffer to: " docx-file-url "\n") | ||
(export-to-docx tm-file-url docx-file-url) | ||
|
||
; Check if the docx file exists | ||
(if (url-exists? docx-file-url) | ||
(display* "Export successful: " docx-file-url "\n") | ||
(display* "Export failed: " docx-file-url "\n")) | ||
|
||
(url-exists? docx-file-url)) | ||
|
||
(define (test_24_15) | ||
(display (url-exists? (system->url "$TEXMACS_PATH/tests/tm/24_15.tm"))) | ||
(let* ((tm-url "$TEXMACS_PATH/tests/tm/24_15.tm") | ||
(docx-url "$TEXMACS_PATH/tests/tm/24_15.docx") | ||
(result (tm->docx tm-url docx-url))) | ||
(check result => #t) | ||
(check-report) | ||
(if (check-failed?) (exit -1)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<TeXmacs|2.1.2> | ||
|
||
<style|<tuple|beamer|chinese|doc>> | ||
|
||
<\body> | ||
<screens|<\shown> | ||
<tit|\<#7B2C\>0\<#8BB2\>\<#FF1A\>\<#521D\>\<#8BC6\>\<#6570\>\<#5B66\>\<#6A21\>\<#5F0F\>> | ||
|
||
<\overlays|2|2> | ||
<\big-table|<tabular|<tformat|<cwith|1|1|1|-1|cell-halign|c>|<cwith|2|-1|2|2|cell-halign|r>|<table|<row|<cell|\<#83DC\>\<#5355\>>|<cell|\<#5FEB\>\<#6377\>\<#952E\>>>|<row|<cell|<menu|Insert|Math|Inline | ||
formula>>|<cell|<key|$>>>|<row|<cell|<menu|Insert|Math|Displayed | ||
formula>>|<cell|<key|A-$>>>|<row|<cell|<menu|Insert|Math|Several | ||
equations>>|<cell|<key|A-&>>>>>>> | ||
\<#8FDB\>\<#5165\>\<#6570\>\<#5B66\>\<#6A21\>\<#5F0F\> | ||
</big-table> | ||
|
||
\<#8FD9\>\<#662F\>\<#4E00\>\<#4E2A\>\<#6BB5\>\<#843D\>\<#FF0C\>\<#5B83\>\<#53EF\>\<#80FD\>\<#662F\>\<#4E00\>\<#884C\>\<#4E5F\>\<#53EF\>\<#80FD\>\<#662F\>\<#591A\>\<#884C\>\<#3002\>\<#8FD9\>\<#662F\>\<#4E00\>\<#4E2A\>\<#884C\>\<#5185\>\<#516C\>\<#5F0F\><math|\<alpha\>+\<beta\>>\<#FF0C\>\<#5B83\>\<#53EF\>\<#4EE5\>\<#88AB\>\<#5D4C\>\<#5165\>\<#5728\>\<#6BB5\>\<#843D\>\<#4E2D\>\<#3002\> | ||
|
||
<\overlay-this|2> | ||
<\big-table|<tabular|<tformat|<cwith|2|2|3|3|cell-row-span|1>|<cwith|2|2|3|3|cell-col-span|2>|<cwith|1|-1|3|4|cell-halign|c>|<table|<row|<cell|\<#7ED3\>\<#6784\>\<#53D8\>\<#5143\>\<#7684\>\<#8F6E\>\<#6362\>>|<cell|\<#884C\>\<#5185\>\<rightarrow\>\<#5355\>\<#884C\>>|<cell|<key|A-S-up>>|<cell|<key|A-S-down>>>|<row|<cell|\<#5207\>\<#6362\>>|<cell|\<#5355\>\<#884C\><math|\<rightarrow\>>\<#591A\>\<#884C\>>|<cell|<key|C-&>>|<cell|>>>>>> | ||
\<#8F6E\>\<#6362\>\<#548C\>\<#5207\>\<#6362\> | ||
</big-table> | ||
|
||
<equation*|<around*|(|x+1|)><rsup|3>=<around*|(|x<rsup|2>+2*x+1|)>*<around*|(|x+1|)>=x<rsup|3>+3*x<rsup|2>+3*x+1> | ||
</overlay-this|> | ||
</overlays> | ||
|
||
\<#672C\>\<#9875\>\<#5E7B\>\<#706F\>\<#7247\>\<#FF1A\>\<#70B9\>\<#51FB\><strong|<menu|Help|Planet>>\<#FF0C\>\<#70B9\>\<#51FB\><strong|\<#4ECE\>\<#96F6\>\<#5F00\>\<#59CB\>\<#5B66\>\<#58A8\>\<#5E72\>\<#7406\>\<#5DE5\>\<#5957\>\<#4EF6\>>\<#5373\>\<#53EF\>\<#627E\>\<#5230\> | ||
|
||
\; | ||
|
||
\; | ||
|
||
\; | ||
</shown>> | ||
</body> | ||
|
||
<\initial> | ||
<\collection> | ||
<associate|info-flag|minimal> | ||
<associate|page-height|auto> | ||
<associate|page-medium|beamer> | ||
<associate|page-screen-margin|false> | ||
<associate|page-type|16:9> | ||
<associate|page-width|auto> | ||
</collection> | ||
</initial> | ||
|
||
<\references> | ||
<\collection> | ||
<associate|auto-1|<tuple|1|1>> | ||
<associate|auto-2|<tuple|1|1>> | ||
<associate|auto-3|<tuple|1|1>> | ||
<associate|auto-4|<tuple|1|1>> | ||
<associate|auto-5|<tuple|2|2>> | ||
<associate|auto-6|<tuple|2|2>> | ||
</collection> | ||
</references> | ||
|
||
<\auxiliary> | ||
<\collection> | ||
<\associate|idx> | ||
<tuple|<tuple|<with|font-family|<quote|ss>|\<#63D2\>\<#5165\>>|<with|font-family|<quote|ss>|\<#6570\>\<#5B66\>>|<with|font-family|<quote|ss>|\<#884C\>\<#5185\>\<#516C\>\<#5F0F\>>>|<pageref|auto-2>> | ||
|
||
<tuple|<tuple|<with|font-family|<quote|ss>|\<#63D2\>\<#5165\>>|<with|font-family|<quote|ss>|\<#6570\>\<#5B66\>>|<with|font-family|<quote|ss>|\<#5355\>\<#884C\>\<#516C\>\<#5F0F\>>>|<pageref|auto-3>> | ||
|
||
<tuple|<tuple|<with|font-family|<quote|ss>|\<#63D2\>\<#5165\>>|<with|font-family|<quote|ss>|\<#6570\>\<#5B66\>>|<with|font-family|<quote|ss>|\<#591A\>\<#884C\>\<#516C\>\<#5F0F\>>>|<pageref|auto-4>> | ||
|
||
<tuple|<tuple|<with|font-family|<quote|ss>|\<#5E2E\>\<#52A9\>>|<with|font-family|<quote|ss>|\<#58A8\>\<#5BA2\>\<#661F\>\<#7403\>>>|<pageref|auto-6>> | ||
</associate> | ||
<\associate|table> | ||
<tuple|normal|<\surround|<hidden-binding|<tuple>|1>|> | ||
\<#8FDB\>\<#5165\>\<#6570\>\<#5B66\>\<#6A21\>\<#5F0F\> | ||
</surround>|<pageref|auto-1>> | ||
|
||
<tuple|normal|<\surround|<hidden-binding|<tuple>|2>|> | ||
\<#8F6E\>\<#6362\>\<#548C\>\<#5207\>\<#6362\> | ||
</surround>|<pageref|auto-5>> | ||
</associate> | ||
</collection> | ||
</auxiliary> |