I have been able to get the script to run with :require
, there was a step which I did not expect—explanation follows. I renamed the style file and that may be relevant although in case it is the pattern of the renaming and of the :require
check which is important, not the name itself.
At the beginning the style was named custom-book-style.ts
and the check that was failing was
(style-has? "custom-book-style")
which was returning #f
(testing Scheme functions is done conveniently in a Scheme session inside your document).
Then I realized that checks for other styles were done in the TeXmacs codes with e.g. (in TeXmacs/progs/kernel/texmacs/tm-modes.scm
)
(in-tmdoc% (style-has? "tmdoc-style"))
but a style named tmdoc-style
does not exist, while a style named tmdoc
exists.
So I changed the name of the style file to custom-book.ts
, but this was not yet enough to get #t
.
Then I added the header, copying it from the “generic” style file and modifying it:
<\active*>
<\src-title>
<src-style-file|custom-book|1.0>
<\src-purpose>
A custom book style.
</src-purpose>
<\src-copyright|1998--2004>
Pycpp
</src-copyright>
<\src-license>
\;
</src-license>
</src-title>
</active*>
(I am leaving the filling of the license field to you )
And now it worked. I did not test what happens with the same header and a different file name (this is why I do not know whether it is the renaming to be important or the header!).
I think this makes it so that only your style file modifies the book title page, and in fact I have been able to go back and forth between book
and custom-book
and see the title page change.
Now there is the issue of forcing the loading of the Scheme file together with the loading of the style file, and I do not know what to do there.
This is the custom-book.ts
I used
<\active*>
<\src-title>
<src-style-file|custom-book|1.0>
<\src-purpose>
A custom book style.
</src-purpose>
<\src-copyright|1998--2004>
Pycpp
</src-copyright>
<\src-license>
\;
</src-license>
</src-title>
</active*>
<use-package|std|env|title-book|header-book|section-book>
<extern| (lambda () (load (url-concretize (url-append (url-head
(current-buffer-url)) "custom-style.scm"))))>
<drd-props|doc-img|border|no>
<assign|doc-img|<macro|x|<arg|x>>>
<\initial>
<\collection>
<associate|page-medium|paper>
<associate|preamble|true>
<associate|src-special|normal>
</collection>
</initial>
\;
and this is the Scheme file
(unless (defined? 'custom-title-flag)
(begin
(tm-define custom-title-flag #t)
(texmacs-modes
(in-custom-style% (style-has? "custom-book-style")))
(tm-define (doc-data-main t)
(:require (in-custom-style?))
`(document
,@(with authors (select t '(doc-author))
(if (<= (length authors) 1) authors
(list `(doc-authors ,@authors))))
(line (point "0par" "0") (point "1par" "0"))
,@(select t '(doc-title))
,@(select t '(doc-subtitle))
,@(select t '(doc-img))
,@(select t '(doc-date))
,@(select t '(doc-misc))
,@(select t '(doc-inactive))))
(menu-bind focus-title-menu
(former)
;;(if (in-custom-style?)
("Image" (make-doc-data-element 'doc-img))
;;)
)))