In each my tm file, I add the follwoing string
<specific|latex|\usepackage{xcolor} \\definecolor{darkgreen}{rgb}{0,.5,0}\\usepackage[colorlinks,filecolor=blue,citecolor=darkgreen,unicode]{hyperref}>
by hands. But I need for this string in each my file. Is it possible to put this string in some place of Texmacs that it will appear in preambule of each my file?
How add something authomatically in preamble?
At the end of this thread there are some hints on how to add things to every new document. I think you could put your command in a style file and then use the commands from there.
How can I add commands to the style file?
I tried it but it doesnāt work in a style file. The following in my-init-buffer.scm
seems to work:
(if (not (buffer-has-name? (current-buffer)))
(begin
(with t (buffer-tree)
(tree-insert! t 0 '((hide-preamble (document (specific "latex" "\\usepackage{xcolor} \\definecolor{darkgreen}{rgb}{0,.5,0}\\usepackage[colorlinks,filecolor=blue,citecolor=darkgreen,unicode]{hyperref}"))) ) ) )
(buffer-pretend-saved (current-buffer))))
It does not work for me. What is a folder for my-init-buffer.scm
? I put it in ~.TeXmacs/progs/my-init-buffer.scm .
Click Tools -> Develop tool
and then click Develop -> Open my-init-buffer.scm
This is the TeXmacs way to open my-init-buffer.scm
.
I made and my file with the above code is opened. Therefore, it is in the correct place?
In my opinion yes! I tried @jeroenās code and for me it worked.
Of course to see the insertion in the preamble you have to start a new file.
Ah, maybe this is the reason. I open my old file with this my-init-buffer.scm and then convert it to latex. In this case it does not work.
I just verified, it works with new file. But it is very strange, why it does not work with already made tm file?
I think it is (I think this without having checked things, but interpreting the file name): my-init-buffer.scm
is executed when a buffer is init
ialized (and I think it acts on that buffer, not on the export command)
Another puzzle appears: how to make an initialization of this file? I tried update -> buffer. Nothing happens.
I believe my-init-buffer.scm
is run for every opened file, but this line prevents the code from running on existing files:
(if (not (buffer-has-name? (current-buffer))))
I donāt think the current code would work on an existing file. I believe it would overwrite the preamble, although I havenāt tested it.
You can append to an existing preamble, but then one would have to check whether the desired command is already in the preamble or not, so as not to add another copy every time the file is opened.
I deleted this part of the code and it works!
I did not understand the question, sorry.
Getting back to what @jeroen wrote, my-init-buffer.scm
is run every time a buffer is initialized.
The line
(if (not (buffer-has-name? (current-buffer))))
makes the code run only for buffers which do not have a name. To have the <specific|latex|...
macro in your file, you do not need to update anything: you just need to start a new file, and it will be there.
@jeroen It overwrites the preamble, I just checked it.
I expect it will work the first time. Judging from @pireddag comments, however, it seems like if you would make any changes to the preamble later, they would be overwritten the next time you open the file.
Perhaps a menu item āappend my LaTeX preambleā would be a good way to handle existing files. You would just need to click it once for existing files. For that the code needs to be changed a bit, though.
I wrote in a misleading way. I meant: if the conditional (if (not (buffer-has-name? (current-buffer)))
is not there, the preamble is overwritten the next time you open the file. If it is there, you get the insertion for a new file and no changes when you open the file later.
āappend my LaTeX preambleā is a good idea. Maybe better to send in savanah as a suggestion?
Itās worth a try. It may take a while for anyone to look at it, developer resources are limited.
Thereās also a wishlist here: https://texmacs.github.io/notes/docs/wishlist.html
I understand. I started to learn scheme and can not be a developer. One question. Where in texmacs source I could find definitions of variables like, for example, buffer-has-name?