Defined command only works in preamble











up vote
2
down vote

favorite












I'm writing a class, and when using it I want to use small caps with a font that doesn't have small caps defined (I know – not as good as the real thing). I found this answer Fake small caps with XeTeX/fontspec? which I tried to include, however I get the errors:



Missing $ inserted.
Missing $ inserted.
You can't use 'spacefactor' in vertical mode.



However, the code works perfectly when it's pasted into the preamble.



Anyone know what's going on?



MWE



Class File



ProvidesClass{custom}[a custom class]
NeedsTeXFormat{LaTeX2e}

DeclareOption*{
PassOptionsToClass{CurrentOption}{scrreprt}
}
ProcessOptionsrelax

LoadClass[usegeometry]{scrreprt}


RequirePackage{graphicx}

RequirePackage{plex-serif}

% Small Caps

makeatletter
newlengthfake@f
newlengthfake@c
deffakesc#1{%
begingroup%
xdeffake@name{csnamecurr@fontshape/f@sizeendcsname}%
fontsize{fontdimen8fake@name}{baselineskip}selectfont%
uppercase{#1}%
endgroup%
}
makeatother

newcommandfauxsc[1]{fauxschelper#1 relaxrelax}
deffauxschelper#1 #2relax{%
fauxschelphelp#1relaxrelax%
ifrelax#2relaxelse fauxschelper#2relaxfi%
}
defHscale{.83}defVscale{.72}defCscale{1.00}
deffauxschelphelp#1#2relax{%
ifnum`#1>``ifnum`#1<`{scalebox{Hscale}[Vscale]{uppercase{#1}}else%
scalebox{Cscale}[1]{#1}fielsescalebox{Cscale}[1]{#1}fi%
ifxrelax#2relaxelsefauxschelphelp#2relaxfi}

makeatletter
newcommand{maketitleee}{
fauxsc{@title}
}
makeatother


Document



documentclass[a4paper, 12pt, oneside]{custom}

title{Title}
author{Author}

begin{document}

maketitleee

end{document}


Update



Removing all the makeatletters and makeatothers seems to change the errors given to those below



Errors



Update 2



This was fixed by @moewe's suggestion, which is replacing fauxsc{@title} with expandafterfauxscexpandafter{@title}










share|improve this question




















  • 2




    Welcome to TeX.SX! Without seeing your code it is impossible to say what the problem is. Can you please add a minimal working example. A MWE should start with a documentclass command, have a minimal preamble and then begin{document}...end{document}. The code should compile and be as small as possible to demonstrate your problem. Cutting your code down to a MWE may well reveal what your problem actually is. In any case, it is really difficult to help you without more information.
    – Andrew
    yesterday






  • 4




    please don't just post disconnected code fragments, post a single small example that we can run to get the error that you are asking about, otherwise it's very hard to guess the error and advise how to fix it.
    – David Carlisle
    yesterday






  • 1




    As David says, please post a full minimal working example: the code should be as small as possible so as to reproduce your error. You should either post a minimal latex document that exhibits the problem or, alternatively, a minimal class file together with a minimal latex document. The key thing is that we should be able to reproduce your error from the code that you post. It is virtually impossible to help you if you don't show us the problem.
    – Andrew
    yesterday








  • 1




    your definition of maketitleee should have the makeatletter/makeatother outside, not inside. There might be other problems (code looks complicated).
    – jfbu
    yesterday






  • 1




    There still is a makeatletter and a makeatother in your .cls file. Remove all makeatletters and makeatothers from the .cls. As I said before if I remove all of them (in the earlier version two pairs, now only one pair), the MWE compiles.
    – moewe
    yesterday

















up vote
2
down vote

favorite












I'm writing a class, and when using it I want to use small caps with a font that doesn't have small caps defined (I know – not as good as the real thing). I found this answer Fake small caps with XeTeX/fontspec? which I tried to include, however I get the errors:



Missing $ inserted.
Missing $ inserted.
You can't use 'spacefactor' in vertical mode.



However, the code works perfectly when it's pasted into the preamble.



Anyone know what's going on?



MWE



Class File



ProvidesClass{custom}[a custom class]
NeedsTeXFormat{LaTeX2e}

DeclareOption*{
PassOptionsToClass{CurrentOption}{scrreprt}
}
ProcessOptionsrelax

LoadClass[usegeometry]{scrreprt}


RequirePackage{graphicx}

RequirePackage{plex-serif}

% Small Caps

makeatletter
newlengthfake@f
newlengthfake@c
deffakesc#1{%
begingroup%
xdeffake@name{csnamecurr@fontshape/f@sizeendcsname}%
fontsize{fontdimen8fake@name}{baselineskip}selectfont%
uppercase{#1}%
endgroup%
}
makeatother

newcommandfauxsc[1]{fauxschelper#1 relaxrelax}
deffauxschelper#1 #2relax{%
fauxschelphelp#1relaxrelax%
ifrelax#2relaxelse fauxschelper#2relaxfi%
}
defHscale{.83}defVscale{.72}defCscale{1.00}
deffauxschelphelp#1#2relax{%
ifnum`#1>``ifnum`#1<`{scalebox{Hscale}[Vscale]{uppercase{#1}}else%
scalebox{Cscale}[1]{#1}fielsescalebox{Cscale}[1]{#1}fi%
ifxrelax#2relaxelsefauxschelphelp#2relaxfi}

makeatletter
newcommand{maketitleee}{
fauxsc{@title}
}
makeatother


Document



documentclass[a4paper, 12pt, oneside]{custom}

title{Title}
author{Author}

begin{document}

maketitleee

end{document}


Update



Removing all the makeatletters and makeatothers seems to change the errors given to those below



Errors



Update 2



This was fixed by @moewe's suggestion, which is replacing fauxsc{@title} with expandafterfauxscexpandafter{@title}










share|improve this question




















  • 2




    Welcome to TeX.SX! Without seeing your code it is impossible to say what the problem is. Can you please add a minimal working example. A MWE should start with a documentclass command, have a minimal preamble and then begin{document}...end{document}. The code should compile and be as small as possible to demonstrate your problem. Cutting your code down to a MWE may well reveal what your problem actually is. In any case, it is really difficult to help you without more information.
    – Andrew
    yesterday






  • 4




    please don't just post disconnected code fragments, post a single small example that we can run to get the error that you are asking about, otherwise it's very hard to guess the error and advise how to fix it.
    – David Carlisle
    yesterday






  • 1




    As David says, please post a full minimal working example: the code should be as small as possible so as to reproduce your error. You should either post a minimal latex document that exhibits the problem or, alternatively, a minimal class file together with a minimal latex document. The key thing is that we should be able to reproduce your error from the code that you post. It is virtually impossible to help you if you don't show us the problem.
    – Andrew
    yesterday








  • 1




    your definition of maketitleee should have the makeatletter/makeatother outside, not inside. There might be other problems (code looks complicated).
    – jfbu
    yesterday






  • 1




    There still is a makeatletter and a makeatother in your .cls file. Remove all makeatletters and makeatothers from the .cls. As I said before if I remove all of them (in the earlier version two pairs, now only one pair), the MWE compiles.
    – moewe
    yesterday















up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm writing a class, and when using it I want to use small caps with a font that doesn't have small caps defined (I know – not as good as the real thing). I found this answer Fake small caps with XeTeX/fontspec? which I tried to include, however I get the errors:



Missing $ inserted.
Missing $ inserted.
You can't use 'spacefactor' in vertical mode.



However, the code works perfectly when it's pasted into the preamble.



Anyone know what's going on?



MWE



Class File



ProvidesClass{custom}[a custom class]
NeedsTeXFormat{LaTeX2e}

DeclareOption*{
PassOptionsToClass{CurrentOption}{scrreprt}
}
ProcessOptionsrelax

LoadClass[usegeometry]{scrreprt}


RequirePackage{graphicx}

RequirePackage{plex-serif}

% Small Caps

makeatletter
newlengthfake@f
newlengthfake@c
deffakesc#1{%
begingroup%
xdeffake@name{csnamecurr@fontshape/f@sizeendcsname}%
fontsize{fontdimen8fake@name}{baselineskip}selectfont%
uppercase{#1}%
endgroup%
}
makeatother

newcommandfauxsc[1]{fauxschelper#1 relaxrelax}
deffauxschelper#1 #2relax{%
fauxschelphelp#1relaxrelax%
ifrelax#2relaxelse fauxschelper#2relaxfi%
}
defHscale{.83}defVscale{.72}defCscale{1.00}
deffauxschelphelp#1#2relax{%
ifnum`#1>``ifnum`#1<`{scalebox{Hscale}[Vscale]{uppercase{#1}}else%
scalebox{Cscale}[1]{#1}fielsescalebox{Cscale}[1]{#1}fi%
ifxrelax#2relaxelsefauxschelphelp#2relaxfi}

makeatletter
newcommand{maketitleee}{
fauxsc{@title}
}
makeatother


Document



documentclass[a4paper, 12pt, oneside]{custom}

title{Title}
author{Author}

begin{document}

maketitleee

end{document}


Update



Removing all the makeatletters and makeatothers seems to change the errors given to those below



Errors



Update 2



This was fixed by @moewe's suggestion, which is replacing fauxsc{@title} with expandafterfauxscexpandafter{@title}










share|improve this question















I'm writing a class, and when using it I want to use small caps with a font that doesn't have small caps defined (I know – not as good as the real thing). I found this answer Fake small caps with XeTeX/fontspec? which I tried to include, however I get the errors:



Missing $ inserted.
Missing $ inserted.
You can't use 'spacefactor' in vertical mode.



However, the code works perfectly when it's pasted into the preamble.



Anyone know what's going on?



MWE



Class File



ProvidesClass{custom}[a custom class]
NeedsTeXFormat{LaTeX2e}

DeclareOption*{
PassOptionsToClass{CurrentOption}{scrreprt}
}
ProcessOptionsrelax

LoadClass[usegeometry]{scrreprt}


RequirePackage{graphicx}

RequirePackage{plex-serif}

% Small Caps

makeatletter
newlengthfake@f
newlengthfake@c
deffakesc#1{%
begingroup%
xdeffake@name{csnamecurr@fontshape/f@sizeendcsname}%
fontsize{fontdimen8fake@name}{baselineskip}selectfont%
uppercase{#1}%
endgroup%
}
makeatother

newcommandfauxsc[1]{fauxschelper#1 relaxrelax}
deffauxschelper#1 #2relax{%
fauxschelphelp#1relaxrelax%
ifrelax#2relaxelse fauxschelper#2relaxfi%
}
defHscale{.83}defVscale{.72}defCscale{1.00}
deffauxschelphelp#1#2relax{%
ifnum`#1>``ifnum`#1<`{scalebox{Hscale}[Vscale]{uppercase{#1}}else%
scalebox{Cscale}[1]{#1}fielsescalebox{Cscale}[1]{#1}fi%
ifxrelax#2relaxelsefauxschelphelp#2relaxfi}

makeatletter
newcommand{maketitleee}{
fauxsc{@title}
}
makeatother


Document



documentclass[a4paper, 12pt, oneside]{custom}

title{Title}
author{Author}

begin{document}

maketitleee

end{document}


Update



Removing all the makeatletters and makeatothers seems to change the errors given to those below



Errors



Update 2



This was fixed by @moewe's suggestion, which is replacing fauxsc{@title} with expandafterfauxscexpandafter{@title}







macros errors documentclass-writing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 22 hours ago

























asked yesterday









tecosaur

1578




1578








  • 2




    Welcome to TeX.SX! Without seeing your code it is impossible to say what the problem is. Can you please add a minimal working example. A MWE should start with a documentclass command, have a minimal preamble and then begin{document}...end{document}. The code should compile and be as small as possible to demonstrate your problem. Cutting your code down to a MWE may well reveal what your problem actually is. In any case, it is really difficult to help you without more information.
    – Andrew
    yesterday






  • 4




    please don't just post disconnected code fragments, post a single small example that we can run to get the error that you are asking about, otherwise it's very hard to guess the error and advise how to fix it.
    – David Carlisle
    yesterday






  • 1




    As David says, please post a full minimal working example: the code should be as small as possible so as to reproduce your error. You should either post a minimal latex document that exhibits the problem or, alternatively, a minimal class file together with a minimal latex document. The key thing is that we should be able to reproduce your error from the code that you post. It is virtually impossible to help you if you don't show us the problem.
    – Andrew
    yesterday








  • 1




    your definition of maketitleee should have the makeatletter/makeatother outside, not inside. There might be other problems (code looks complicated).
    – jfbu
    yesterday






  • 1




    There still is a makeatletter and a makeatother in your .cls file. Remove all makeatletters and makeatothers from the .cls. As I said before if I remove all of them (in the earlier version two pairs, now only one pair), the MWE compiles.
    – moewe
    yesterday
















  • 2




    Welcome to TeX.SX! Without seeing your code it is impossible to say what the problem is. Can you please add a minimal working example. A MWE should start with a documentclass command, have a minimal preamble and then begin{document}...end{document}. The code should compile and be as small as possible to demonstrate your problem. Cutting your code down to a MWE may well reveal what your problem actually is. In any case, it is really difficult to help you without more information.
    – Andrew
    yesterday






  • 4




    please don't just post disconnected code fragments, post a single small example that we can run to get the error that you are asking about, otherwise it's very hard to guess the error and advise how to fix it.
    – David Carlisle
    yesterday






  • 1




    As David says, please post a full minimal working example: the code should be as small as possible so as to reproduce your error. You should either post a minimal latex document that exhibits the problem or, alternatively, a minimal class file together with a minimal latex document. The key thing is that we should be able to reproduce your error from the code that you post. It is virtually impossible to help you if you don't show us the problem.
    – Andrew
    yesterday








  • 1




    your definition of maketitleee should have the makeatletter/makeatother outside, not inside. There might be other problems (code looks complicated).
    – jfbu
    yesterday






  • 1




    There still is a makeatletter and a makeatother in your .cls file. Remove all makeatletters and makeatothers from the .cls. As I said before if I remove all of them (in the earlier version two pairs, now only one pair), the MWE compiles.
    – moewe
    yesterday










2




2




Welcome to TeX.SX! Without seeing your code it is impossible to say what the problem is. Can you please add a minimal working example. A MWE should start with a documentclass command, have a minimal preamble and then begin{document}...end{document}. The code should compile and be as small as possible to demonstrate your problem. Cutting your code down to a MWE may well reveal what your problem actually is. In any case, it is really difficult to help you without more information.
– Andrew
yesterday




Welcome to TeX.SX! Without seeing your code it is impossible to say what the problem is. Can you please add a minimal working example. A MWE should start with a documentclass command, have a minimal preamble and then begin{document}...end{document}. The code should compile and be as small as possible to demonstrate your problem. Cutting your code down to a MWE may well reveal what your problem actually is. In any case, it is really difficult to help you without more information.
– Andrew
yesterday




4




4




please don't just post disconnected code fragments, post a single small example that we can run to get the error that you are asking about, otherwise it's very hard to guess the error and advise how to fix it.
– David Carlisle
yesterday




please don't just post disconnected code fragments, post a single small example that we can run to get the error that you are asking about, otherwise it's very hard to guess the error and advise how to fix it.
– David Carlisle
yesterday




1




1




As David says, please post a full minimal working example: the code should be as small as possible so as to reproduce your error. You should either post a minimal latex document that exhibits the problem or, alternatively, a minimal class file together with a minimal latex document. The key thing is that we should be able to reproduce your error from the code that you post. It is virtually impossible to help you if you don't show us the problem.
– Andrew
yesterday






As David says, please post a full minimal working example: the code should be as small as possible so as to reproduce your error. You should either post a minimal latex document that exhibits the problem or, alternatively, a minimal class file together with a minimal latex document. The key thing is that we should be able to reproduce your error from the code that you post. It is virtually impossible to help you if you don't show us the problem.
– Andrew
yesterday






1




1




your definition of maketitleee should have the makeatletter/makeatother outside, not inside. There might be other problems (code looks complicated).
– jfbu
yesterday




your definition of maketitleee should have the makeatletter/makeatother outside, not inside. There might be other problems (code looks complicated).
– jfbu
yesterday




1




1




There still is a makeatletter and a makeatother in your .cls file. Remove all makeatletters and makeatothers from the .cls. As I said before if I remove all of them (in the earlier version two pairs, now only one pair), the MWE compiles.
– moewe
yesterday






There still is a makeatletter and a makeatother in your .cls file. Remove all makeatletters and makeatothers from the .cls. As I said before if I remove all of them (in the earlier version two pairs, now only one pair), the MWE compiles.
– moewe
yesterday












1 Answer
1






active

oldest

votes

















up vote
5
down vote



accepted










First and foremost: faking small caps for a font that hasn't them is hopeless.





When LaTeX is reading a .cls file, makeatletter is implicitly in force and issuing makeatother will most likely introduce problems.



Indeed it does, because when we arrive at defining maketitlee, @ is an “other character”, so the definition becomes



• •makeatletter•@•t•i•t•l•e•makeatother•


( is used to separate tokens). Note that when maketitlee is called, the replacement text has already been tokenized, so makeatletter will do nothing at all.



Never use makeatletter and makeatother in a .cls file except in the body of a macro definition that has among its actions inputting a file where the special treatment of @ is needed. This is not the case of your maketitlee macro.





After removing makeatletter and makeatother everywhere in the class file, compiling your example .tex file produces no error and the output is



enter image description here



that clearly shows what I mean in the top line of this answer.






share|improve this answer























  • I see, however — if I remove the makeatletter and makeatother it doesn't work.
    – tecosaur
    yesterday












  • @tecosaur I tried, of course.
    – egreg
    yesterday










  • Something that may throw a spanner in the works, after seeing this comment tex.stackexchange.com/questions/459738/… I realised I needed to modify the MWE given, for me that MWE doesn't successfully compile.
    – tecosaur
    23 hours ago










  • However, this does solve the issue which I had (at least the first one). Thanks :)
    – tecosaur
    22 hours ago






  • 3




    In some situations better than makeatletter..makeatother is: begingroupmakeatletter@firstofone{endgroup <Stuff where @ must be letter>} . This way the category code of @ will be reset to whatever it was before issuing the makeatletter-command. makeatother does set the category code of @ to 12 (other) no matter what it was before.
    – Ulrich Diez
    21 hours ago













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f459738%2fdefined-command-only-works-in-preamble%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote



accepted










First and foremost: faking small caps for a font that hasn't them is hopeless.





When LaTeX is reading a .cls file, makeatletter is implicitly in force and issuing makeatother will most likely introduce problems.



Indeed it does, because when we arrive at defining maketitlee, @ is an “other character”, so the definition becomes



• •makeatletter•@•t•i•t•l•e•makeatother•


( is used to separate tokens). Note that when maketitlee is called, the replacement text has already been tokenized, so makeatletter will do nothing at all.



Never use makeatletter and makeatother in a .cls file except in the body of a macro definition that has among its actions inputting a file where the special treatment of @ is needed. This is not the case of your maketitlee macro.





After removing makeatletter and makeatother everywhere in the class file, compiling your example .tex file produces no error and the output is



enter image description here



that clearly shows what I mean in the top line of this answer.






share|improve this answer























  • I see, however — if I remove the makeatletter and makeatother it doesn't work.
    – tecosaur
    yesterday












  • @tecosaur I tried, of course.
    – egreg
    yesterday










  • Something that may throw a spanner in the works, after seeing this comment tex.stackexchange.com/questions/459738/… I realised I needed to modify the MWE given, for me that MWE doesn't successfully compile.
    – tecosaur
    23 hours ago










  • However, this does solve the issue which I had (at least the first one). Thanks :)
    – tecosaur
    22 hours ago






  • 3




    In some situations better than makeatletter..makeatother is: begingroupmakeatletter@firstofone{endgroup <Stuff where @ must be letter>} . This way the category code of @ will be reset to whatever it was before issuing the makeatletter-command. makeatother does set the category code of @ to 12 (other) no matter what it was before.
    – Ulrich Diez
    21 hours ago

















up vote
5
down vote



accepted










First and foremost: faking small caps for a font that hasn't them is hopeless.





When LaTeX is reading a .cls file, makeatletter is implicitly in force and issuing makeatother will most likely introduce problems.



Indeed it does, because when we arrive at defining maketitlee, @ is an “other character”, so the definition becomes



• •makeatletter•@•t•i•t•l•e•makeatother•


( is used to separate tokens). Note that when maketitlee is called, the replacement text has already been tokenized, so makeatletter will do nothing at all.



Never use makeatletter and makeatother in a .cls file except in the body of a macro definition that has among its actions inputting a file where the special treatment of @ is needed. This is not the case of your maketitlee macro.





After removing makeatletter and makeatother everywhere in the class file, compiling your example .tex file produces no error and the output is



enter image description here



that clearly shows what I mean in the top line of this answer.






share|improve this answer























  • I see, however — if I remove the makeatletter and makeatother it doesn't work.
    – tecosaur
    yesterday












  • @tecosaur I tried, of course.
    – egreg
    yesterday










  • Something that may throw a spanner in the works, after seeing this comment tex.stackexchange.com/questions/459738/… I realised I needed to modify the MWE given, for me that MWE doesn't successfully compile.
    – tecosaur
    23 hours ago










  • However, this does solve the issue which I had (at least the first one). Thanks :)
    – tecosaur
    22 hours ago






  • 3




    In some situations better than makeatletter..makeatother is: begingroupmakeatletter@firstofone{endgroup <Stuff where @ must be letter>} . This way the category code of @ will be reset to whatever it was before issuing the makeatletter-command. makeatother does set the category code of @ to 12 (other) no matter what it was before.
    – Ulrich Diez
    21 hours ago















up vote
5
down vote



accepted







up vote
5
down vote



accepted






First and foremost: faking small caps for a font that hasn't them is hopeless.





When LaTeX is reading a .cls file, makeatletter is implicitly in force and issuing makeatother will most likely introduce problems.



Indeed it does, because when we arrive at defining maketitlee, @ is an “other character”, so the definition becomes



• •makeatletter•@•t•i•t•l•e•makeatother•


( is used to separate tokens). Note that when maketitlee is called, the replacement text has already been tokenized, so makeatletter will do nothing at all.



Never use makeatletter and makeatother in a .cls file except in the body of a macro definition that has among its actions inputting a file where the special treatment of @ is needed. This is not the case of your maketitlee macro.





After removing makeatletter and makeatother everywhere in the class file, compiling your example .tex file produces no error and the output is



enter image description here



that clearly shows what I mean in the top line of this answer.






share|improve this answer














First and foremost: faking small caps for a font that hasn't them is hopeless.





When LaTeX is reading a .cls file, makeatletter is implicitly in force and issuing makeatother will most likely introduce problems.



Indeed it does, because when we arrive at defining maketitlee, @ is an “other character”, so the definition becomes



• •makeatletter•@•t•i•t•l•e•makeatother•


( is used to separate tokens). Note that when maketitlee is called, the replacement text has already been tokenized, so makeatletter will do nothing at all.



Never use makeatletter and makeatother in a .cls file except in the body of a macro definition that has among its actions inputting a file where the special treatment of @ is needed. This is not the case of your maketitlee macro.





After removing makeatletter and makeatother everywhere in the class file, compiling your example .tex file produces no error and the output is



enter image description here



that clearly shows what I mean in the top line of this answer.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









egreg

697k8518503115




697k8518503115












  • I see, however — if I remove the makeatletter and makeatother it doesn't work.
    – tecosaur
    yesterday












  • @tecosaur I tried, of course.
    – egreg
    yesterday










  • Something that may throw a spanner in the works, after seeing this comment tex.stackexchange.com/questions/459738/… I realised I needed to modify the MWE given, for me that MWE doesn't successfully compile.
    – tecosaur
    23 hours ago










  • However, this does solve the issue which I had (at least the first one). Thanks :)
    – tecosaur
    22 hours ago






  • 3




    In some situations better than makeatletter..makeatother is: begingroupmakeatletter@firstofone{endgroup <Stuff where @ must be letter>} . This way the category code of @ will be reset to whatever it was before issuing the makeatletter-command. makeatother does set the category code of @ to 12 (other) no matter what it was before.
    – Ulrich Diez
    21 hours ago




















  • I see, however — if I remove the makeatletter and makeatother it doesn't work.
    – tecosaur
    yesterday












  • @tecosaur I tried, of course.
    – egreg
    yesterday










  • Something that may throw a spanner in the works, after seeing this comment tex.stackexchange.com/questions/459738/… I realised I needed to modify the MWE given, for me that MWE doesn't successfully compile.
    – tecosaur
    23 hours ago










  • However, this does solve the issue which I had (at least the first one). Thanks :)
    – tecosaur
    22 hours ago






  • 3




    In some situations better than makeatletter..makeatother is: begingroupmakeatletter@firstofone{endgroup <Stuff where @ must be letter>} . This way the category code of @ will be reset to whatever it was before issuing the makeatletter-command. makeatother does set the category code of @ to 12 (other) no matter what it was before.
    – Ulrich Diez
    21 hours ago


















I see, however — if I remove the makeatletter and makeatother it doesn't work.
– tecosaur
yesterday






I see, however — if I remove the makeatletter and makeatother it doesn't work.
– tecosaur
yesterday














@tecosaur I tried, of course.
– egreg
yesterday




@tecosaur I tried, of course.
– egreg
yesterday












Something that may throw a spanner in the works, after seeing this comment tex.stackexchange.com/questions/459738/… I realised I needed to modify the MWE given, for me that MWE doesn't successfully compile.
– tecosaur
23 hours ago




Something that may throw a spanner in the works, after seeing this comment tex.stackexchange.com/questions/459738/… I realised I needed to modify the MWE given, for me that MWE doesn't successfully compile.
– tecosaur
23 hours ago












However, this does solve the issue which I had (at least the first one). Thanks :)
– tecosaur
22 hours ago




However, this does solve the issue which I had (at least the first one). Thanks :)
– tecosaur
22 hours ago




3




3




In some situations better than makeatletter..makeatother is: begingroupmakeatletter@firstofone{endgroup <Stuff where @ must be letter>} . This way the category code of @ will be reset to whatever it was before issuing the makeatletter-command. makeatother does set the category code of @ to 12 (other) no matter what it was before.
– Ulrich Diez
21 hours ago






In some situations better than makeatletter..makeatother is: begingroupmakeatletter@firstofone{endgroup <Stuff where @ must be letter>} . This way the category code of @ will be reset to whatever it was before issuing the makeatletter-command. makeatother does set the category code of @ to 12 (other) no matter what it was before.
– Ulrich Diez
21 hours ago




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f459738%2fdefined-command-only-works-in-preamble%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

Probability when a professor distributes a quiz and homework assignment to a class of n students.

Aardman Animations

Are they similar matrix