How to export user defined macros to Latex?

I have defined a macro that helps me type formulas
image
it works fine when I type \seq and a
image
But when I export the formula typed with the macro I get $\seq{a}$, but not $a_1,\cdots,a_n$ as I want. I have tried expand user defined macros in the preference but nothing has changed.
Is it possible to achieve what I am expecting?

Where do you define the macro? In the document or in the preamble?

In my document. I am just experimenting with macros.

Try putting it in the preamble (Document -> Part -> Show preamble).

With expand user defined macros enabled, I get $v_1, \ldots, v_n$ in the document part of the LaTeX file.

With expand user defined macros disabled, I get \newcommand{\seq}[1]{#1_1, \ldots, #1_n} in the LaTeX preamble and $\seq{v}$ in the document.

1 Like

There seem some issues when we redefine some macros, even after de-selecting Expand TeXmacs macros with no LaTeX equivalents.

For example,

<TeXmacs|2.1>

<style|<tuple|generic|french>>

<\body>
  <\hide-preamble>
    <assign|dfn|<macro|body|``<arg|body>''>>
  </hide-preamble>

  A <dfn|group> is a set <math|G> along with a multiplication
  <math|<around*|(|\<cdummy\>|)>*<around*|(|\<cdummy\>|)>\<of\>G\<times\>G\<rightarrow\>G>
  such that
</body>

<\initial>
  <\collection>
    <associate|page-medium|paper>
  </collection>
</initial>

is exported to

\documentclass{article}
\usepackage[french]{babel}

%%%%%%%%%% Start TeXmacs macros
\newcommand{\cdummy}{\cdot}
\newcommand{\of}{:}
\newcommand{\tmdfn}[1]{\textbf{#1}}
%%%%%%%%%% End TeXmacs macros

\begin{document}

A {\tmdfn{group}} is a set $G$ along with a multiplication $(\cdummy) 
(\cdummy) \of G \times G \rightarrow G$ such that

\end{document}
1 Like

I tried to put the following in to the preamble
image
But when I go back to document and type \seq I get:
image
Note that wierd bar in the second line.
Would you please give a more detailed explaination on how to do this? Thank you in advance!

The problem is the fact that you typed the math tag in multiple lines, retype it without going to the line (this is meaningful in TeXmacs), e.g. exactly how you did it in your first post. Then should be ok.

NB: It is usually good time spent if you go through the online help, especially “Help->Manual” and for macros “Help->Manual->Write your own style files”. Best of all Joris’ book “The Jolly Writer” explains in detail many useful topics.

1 Like

Indeed, it seems that TeXmacs does not care about the preamble when exporting this to LaTeX. What if you put the redefinition in a style file?

Is it possible to copy to Latex with user defined macros enabled? I just want to copy a line from the .tm file and generate a whole .tex file seems kind of heavy to me.

Well, I’ve never tried but you can select the content, and the do “Copy to -> LaTeX” and check what TeXmacs does. My guess is that it will not expand the macro. If you think about it, in general what you would like to achieve is not easy. If I would have to do it, the easier whay is to export the whole document or write myself the LaTeX macros I would like to have. TeXmacs is not optimized for interoperability with LaTeX.

It will expand if the definition of the macro is in the preamble, if the option Expand user-defined macros is enabled in User preferences. However, Copy to LaTeX is very unreliable. For example, when there are two lines, it will produce a strange unicode.

By the way, there is a usage of this Copy to LaTeX: writing a question or an answer on Math StackExchange, say.

I don’t know whether I did something incorrectly. If I extract the style file from the Focus menu and load this style file, when inputting the macro \dfn, it is even undefined (shown as red). On the other hand, if I extract the style package, the macro works but the export to LaTeX still ignores this.