Expand all newcommand without doing anything else in LaTeX? [duplicate]











up vote
0
down vote

favorite
1













This question already has an answer here:




  • LaTeX macro expander

    7 answers




Can I expand all newcommands without doing anything else in LaTeX?



Edited: My true goal is standardizing math papers in plain text so that theorems and definitions can be accurately and easily extracted without losing mathematical symbols.










share|improve this question















marked as duplicate by Werner macros
Users with the  macros badge can single-handedly close macros questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 21:43


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • No (maybe there exists an external program to preprocess your LaTeX file)
    – Henri Menke
    Nov 19 at 21:02










  • @HenriMenke Yeah I think I will just write one. It shouldn't be hard. It's pretty much just putting all new commands into a python dictionary and recursively substituting them to the point that they are all gone.
    – Ying Zhou
    Nov 19 at 21:04

















up vote
0
down vote

favorite
1













This question already has an answer here:




  • LaTeX macro expander

    7 answers




Can I expand all newcommands without doing anything else in LaTeX?



Edited: My true goal is standardizing math papers in plain text so that theorems and definitions can be accurately and easily extracted without losing mathematical symbols.










share|improve this question















marked as duplicate by Werner macros
Users with the  macros badge can single-handedly close macros questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 21:43


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • No (maybe there exists an external program to preprocess your LaTeX file)
    – Henri Menke
    Nov 19 at 21:02










  • @HenriMenke Yeah I think I will just write one. It shouldn't be hard. It's pretty much just putting all new commands into a python dictionary and recursively substituting them to the point that they are all gone.
    – Ying Zhou
    Nov 19 at 21:04















up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1






This question already has an answer here:




  • LaTeX macro expander

    7 answers




Can I expand all newcommands without doing anything else in LaTeX?



Edited: My true goal is standardizing math papers in plain text so that theorems and definitions can be accurately and easily extracted without losing mathematical symbols.










share|improve this question
















This question already has an answer here:




  • LaTeX macro expander

    7 answers




Can I expand all newcommands without doing anything else in LaTeX?



Edited: My true goal is standardizing math papers in plain text so that theorems and definitions can be accurately and easily extracted without losing mathematical symbols.





This question already has an answer here:




  • LaTeX macro expander

    7 answers








macros






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 21:06

























asked Nov 19 at 20:43









Ying Zhou

687




687




marked as duplicate by Werner macros
Users with the  macros badge can single-handedly close macros questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 21:43


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Werner macros
Users with the  macros badge can single-handedly close macros questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 21:43


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • No (maybe there exists an external program to preprocess your LaTeX file)
    – Henri Menke
    Nov 19 at 21:02










  • @HenriMenke Yeah I think I will just write one. It shouldn't be hard. It's pretty much just putting all new commands into a python dictionary and recursively substituting them to the point that they are all gone.
    – Ying Zhou
    Nov 19 at 21:04




















  • No (maybe there exists an external program to preprocess your LaTeX file)
    – Henri Menke
    Nov 19 at 21:02










  • @HenriMenke Yeah I think I will just write one. It shouldn't be hard. It's pretty much just putting all new commands into a python dictionary and recursively substituting them to the point that they are all gone.
    – Ying Zhou
    Nov 19 at 21:04


















No (maybe there exists an external program to preprocess your LaTeX file)
– Henri Menke
Nov 19 at 21:02




No (maybe there exists an external program to preprocess your LaTeX file)
– Henri Menke
Nov 19 at 21:02












@HenriMenke Yeah I think I will just write one. It shouldn't be hard. It's pretty much just putting all new commands into a python dictionary and recursively substituting them to the point that they are all gone.
– Ying Zhou
Nov 19 at 21:04






@HenriMenke Yeah I think I will just write one. It shouldn't be hard. It's pretty much just putting all new commands into a python dictionary and recursively substituting them to the point that they are all gone.
– Ying Zhou
Nov 19 at 21:04












1 Answer
1






active

oldest

votes

















up vote
5
down vote



accepted










There are several existing programs that do this in limited contexts for example



https://ctan.org/tex-archive/support/de-macro



However it is in general not possible to expand all macros without a full tex execution.



Consider



newcommandfoo{ifxzzzundefined noelse yesfi}


which expands to no or yes depending on the state of TeX at that time or



newcommandfoo{sbox0{hello}ifdimwd0>2cm yeselse nofi}


which expands to no or yes depending on the width of some text set in the current font.



In simple cases the document will behave the same way if you expand the macros but for example if you expand zzz (and remove its definition) then the expansion of foo will change.



If however you are restricting to expanding out simple shortcut macros used for authoring convenience, which contain no conditional or recursive calls then simple string replacement in any text processing tool will probably do the right thing, on a good day.






share|improve this answer





















  • Also consider that a phrase of tex-input might yield different tokens/different replacement depending on the catcode-régime at the time of tokenizing. newcommandfoobar{...} versus verb|foobar| or stringfoobar or csname foobarmacroendcsname. (In the latter case, the result depends on the definition of macro.) Or catcoder=13... def r{<something>}...foobar... Besides this let-assignments might be nice, too: newcommandfoobar{...}` ... letfoobar=whatsoever...whatsoever.
    – Ulrich Diez
    Nov 20 at 10:10










  • @UlrichDiez I managed to avoid including a copy of xii.tex in this answer, don't tempt me:-)
    – David Carlisle
    Nov 20 at 10:45










  • I like your xii.tex. It reminds me of Michael Downes' Around the Bend questions 10 and 11 (Obfuscated TeX code / Decoding obfuscated TeX code).
    – Ulrich Diez
    Nov 20 at 11:00


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote



accepted










There are several existing programs that do this in limited contexts for example



https://ctan.org/tex-archive/support/de-macro



However it is in general not possible to expand all macros without a full tex execution.



Consider



newcommandfoo{ifxzzzundefined noelse yesfi}


which expands to no or yes depending on the state of TeX at that time or



newcommandfoo{sbox0{hello}ifdimwd0>2cm yeselse nofi}


which expands to no or yes depending on the width of some text set in the current font.



In simple cases the document will behave the same way if you expand the macros but for example if you expand zzz (and remove its definition) then the expansion of foo will change.



If however you are restricting to expanding out simple shortcut macros used for authoring convenience, which contain no conditional or recursive calls then simple string replacement in any text processing tool will probably do the right thing, on a good day.






share|improve this answer





















  • Also consider that a phrase of tex-input might yield different tokens/different replacement depending on the catcode-régime at the time of tokenizing. newcommandfoobar{...} versus verb|foobar| or stringfoobar or csname foobarmacroendcsname. (In the latter case, the result depends on the definition of macro.) Or catcoder=13... def r{<something>}...foobar... Besides this let-assignments might be nice, too: newcommandfoobar{...}` ... letfoobar=whatsoever...whatsoever.
    – Ulrich Diez
    Nov 20 at 10:10










  • @UlrichDiez I managed to avoid including a copy of xii.tex in this answer, don't tempt me:-)
    – David Carlisle
    Nov 20 at 10:45










  • I like your xii.tex. It reminds me of Michael Downes' Around the Bend questions 10 and 11 (Obfuscated TeX code / Decoding obfuscated TeX code).
    – Ulrich Diez
    Nov 20 at 11:00















up vote
5
down vote



accepted










There are several existing programs that do this in limited contexts for example



https://ctan.org/tex-archive/support/de-macro



However it is in general not possible to expand all macros without a full tex execution.



Consider



newcommandfoo{ifxzzzundefined noelse yesfi}


which expands to no or yes depending on the state of TeX at that time or



newcommandfoo{sbox0{hello}ifdimwd0>2cm yeselse nofi}


which expands to no or yes depending on the width of some text set in the current font.



In simple cases the document will behave the same way if you expand the macros but for example if you expand zzz (and remove its definition) then the expansion of foo will change.



If however you are restricting to expanding out simple shortcut macros used for authoring convenience, which contain no conditional or recursive calls then simple string replacement in any text processing tool will probably do the right thing, on a good day.






share|improve this answer





















  • Also consider that a phrase of tex-input might yield different tokens/different replacement depending on the catcode-régime at the time of tokenizing. newcommandfoobar{...} versus verb|foobar| or stringfoobar or csname foobarmacroendcsname. (In the latter case, the result depends on the definition of macro.) Or catcoder=13... def r{<something>}...foobar... Besides this let-assignments might be nice, too: newcommandfoobar{...}` ... letfoobar=whatsoever...whatsoever.
    – Ulrich Diez
    Nov 20 at 10:10










  • @UlrichDiez I managed to avoid including a copy of xii.tex in this answer, don't tempt me:-)
    – David Carlisle
    Nov 20 at 10:45










  • I like your xii.tex. It reminds me of Michael Downes' Around the Bend questions 10 and 11 (Obfuscated TeX code / Decoding obfuscated TeX code).
    – Ulrich Diez
    Nov 20 at 11:00













up vote
5
down vote



accepted







up vote
5
down vote



accepted






There are several existing programs that do this in limited contexts for example



https://ctan.org/tex-archive/support/de-macro



However it is in general not possible to expand all macros without a full tex execution.



Consider



newcommandfoo{ifxzzzundefined noelse yesfi}


which expands to no or yes depending on the state of TeX at that time or



newcommandfoo{sbox0{hello}ifdimwd0>2cm yeselse nofi}


which expands to no or yes depending on the width of some text set in the current font.



In simple cases the document will behave the same way if you expand the macros but for example if you expand zzz (and remove its definition) then the expansion of foo will change.



If however you are restricting to expanding out simple shortcut macros used for authoring convenience, which contain no conditional or recursive calls then simple string replacement in any text processing tool will probably do the right thing, on a good day.






share|improve this answer












There are several existing programs that do this in limited contexts for example



https://ctan.org/tex-archive/support/de-macro



However it is in general not possible to expand all macros without a full tex execution.



Consider



newcommandfoo{ifxzzzundefined noelse yesfi}


which expands to no or yes depending on the state of TeX at that time or



newcommandfoo{sbox0{hello}ifdimwd0>2cm yeselse nofi}


which expands to no or yes depending on the width of some text set in the current font.



In simple cases the document will behave the same way if you expand the macros but for example if you expand zzz (and remove its definition) then the expansion of foo will change.



If however you are restricting to expanding out simple shortcut macros used for authoring convenience, which contain no conditional or recursive calls then simple string replacement in any text processing tool will probably do the right thing, on a good day.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 21:36









David Carlisle

477k3811061841




477k3811061841












  • Also consider that a phrase of tex-input might yield different tokens/different replacement depending on the catcode-régime at the time of tokenizing. newcommandfoobar{...} versus verb|foobar| or stringfoobar or csname foobarmacroendcsname. (In the latter case, the result depends on the definition of macro.) Or catcoder=13... def r{<something>}...foobar... Besides this let-assignments might be nice, too: newcommandfoobar{...}` ... letfoobar=whatsoever...whatsoever.
    – Ulrich Diez
    Nov 20 at 10:10










  • @UlrichDiez I managed to avoid including a copy of xii.tex in this answer, don't tempt me:-)
    – David Carlisle
    Nov 20 at 10:45










  • I like your xii.tex. It reminds me of Michael Downes' Around the Bend questions 10 and 11 (Obfuscated TeX code / Decoding obfuscated TeX code).
    – Ulrich Diez
    Nov 20 at 11:00


















  • Also consider that a phrase of tex-input might yield different tokens/different replacement depending on the catcode-régime at the time of tokenizing. newcommandfoobar{...} versus verb|foobar| or stringfoobar or csname foobarmacroendcsname. (In the latter case, the result depends on the definition of macro.) Or catcoder=13... def r{<something>}...foobar... Besides this let-assignments might be nice, too: newcommandfoobar{...}` ... letfoobar=whatsoever...whatsoever.
    – Ulrich Diez
    Nov 20 at 10:10










  • @UlrichDiez I managed to avoid including a copy of xii.tex in this answer, don't tempt me:-)
    – David Carlisle
    Nov 20 at 10:45










  • I like your xii.tex. It reminds me of Michael Downes' Around the Bend questions 10 and 11 (Obfuscated TeX code / Decoding obfuscated TeX code).
    – Ulrich Diez
    Nov 20 at 11:00
















Also consider that a phrase of tex-input might yield different tokens/different replacement depending on the catcode-régime at the time of tokenizing. newcommandfoobar{...} versus verb|foobar| or stringfoobar or csname foobarmacroendcsname. (In the latter case, the result depends on the definition of macro.) Or catcoder=13... def r{<something>}...foobar... Besides this let-assignments might be nice, too: newcommandfoobar{...}` ... letfoobar=whatsoever...whatsoever.
– Ulrich Diez
Nov 20 at 10:10




Also consider that a phrase of tex-input might yield different tokens/different replacement depending on the catcode-régime at the time of tokenizing. newcommandfoobar{...} versus verb|foobar| or stringfoobar or csname foobarmacroendcsname. (In the latter case, the result depends on the definition of macro.) Or catcoder=13... def r{<something>}...foobar... Besides this let-assignments might be nice, too: newcommandfoobar{...}` ... letfoobar=whatsoever...whatsoever.
– Ulrich Diez
Nov 20 at 10:10












@UlrichDiez I managed to avoid including a copy of xii.tex in this answer, don't tempt me:-)
– David Carlisle
Nov 20 at 10:45




@UlrichDiez I managed to avoid including a copy of xii.tex in this answer, don't tempt me:-)
– David Carlisle
Nov 20 at 10:45












I like your xii.tex. It reminds me of Michael Downes' Around the Bend questions 10 and 11 (Obfuscated TeX code / Decoding obfuscated TeX code).
– Ulrich Diez
Nov 20 at 11:00




I like your xii.tex. It reminds me of Michael Downes' Around the Bend questions 10 and 11 (Obfuscated TeX code / Decoding obfuscated TeX code).
– Ulrich Diez
Nov 20 at 11:00



Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?