How to define and use macro in Mathjax?
I often use vector operation, and normally vector is written by Bold font, e.g.
$$ boldsymbol x = boldsymbol a times boldsymbol b + boldsymbol c $$
which is somehow too long, so I like to define some new commands bx, ba, bb first,
$$
newcommand{bx}{boldsymbol x}
newcommand{ba}{boldsymbol a}
newcommand{bb}{boldsymbol b}
newcommand{bc}{boldsymbol c}
$$
then above equation can be written shortly as:
$$ bx = ba times bb + bc $$
Because I use these Bold fonts so often, I don't want to type them time by time, I plan to define them as macro in a file: boldfont.js , when I need to type vector, I just require boldfont.js.
I write file as follows (save the file as: /config/TeX/boldfont.js, other file (such as color.js) under the same directory):
MathJax.Hub.Config({
TeX: {
Macros: {
ba: '{\boldsymbol a}',
bb: '{\boldsymbol b}',
bc: '{\boldsymbol c}',
bd: '{\boldsymbol d}',
be: '{\boldsymbol e}',
bf: '{\boldsymbol f}',
bg: '{\boldsymbol g}',
bh: '{\boldsymbol h}',
bi: '{\boldsymbol i}',
bj: '{\boldsymbol j}',
bk: '{\boldsymbol k}',
bl: '{\boldsymbol l}',
bm: '{\boldsymbol m}',
bn: '{\boldsymbol n}',
bo: '{\boldsymbol o}',
bp: '{\boldsymbol p}',
bq: '{\boldsymbol q}',
br: '{\boldsymbol r}',
bs: '{\boldsymbol s}',
bt: '{\boldsymbol t}',
bu: '{\boldsymbol u}',
bv: '{\boldsymbol v}',
bw: '{\boldsymbol w}',
bx: '{\boldsymbol x}',
by: '{\boldsymbol y}',
bz: '{\boldsymbol z}',
}
}
});
And I try to use the file (using require command) as
$$
require{boldfont}
bf=bu+bv-bw
$$
But it doesn't work, what's wrong? How to define macro and use it?
Help me, please.
require mathjax
add a comment |
I often use vector operation, and normally vector is written by Bold font, e.g.
$$ boldsymbol x = boldsymbol a times boldsymbol b + boldsymbol c $$
which is somehow too long, so I like to define some new commands bx, ba, bb first,
$$
newcommand{bx}{boldsymbol x}
newcommand{ba}{boldsymbol a}
newcommand{bb}{boldsymbol b}
newcommand{bc}{boldsymbol c}
$$
then above equation can be written shortly as:
$$ bx = ba times bb + bc $$
Because I use these Bold fonts so often, I don't want to type them time by time, I plan to define them as macro in a file: boldfont.js , when I need to type vector, I just require boldfont.js.
I write file as follows (save the file as: /config/TeX/boldfont.js, other file (such as color.js) under the same directory):
MathJax.Hub.Config({
TeX: {
Macros: {
ba: '{\boldsymbol a}',
bb: '{\boldsymbol b}',
bc: '{\boldsymbol c}',
bd: '{\boldsymbol d}',
be: '{\boldsymbol e}',
bf: '{\boldsymbol f}',
bg: '{\boldsymbol g}',
bh: '{\boldsymbol h}',
bi: '{\boldsymbol i}',
bj: '{\boldsymbol j}',
bk: '{\boldsymbol k}',
bl: '{\boldsymbol l}',
bm: '{\boldsymbol m}',
bn: '{\boldsymbol n}',
bo: '{\boldsymbol o}',
bp: '{\boldsymbol p}',
bq: '{\boldsymbol q}',
br: '{\boldsymbol r}',
bs: '{\boldsymbol s}',
bt: '{\boldsymbol t}',
bu: '{\boldsymbol u}',
bv: '{\boldsymbol v}',
bw: '{\boldsymbol w}',
bx: '{\boldsymbol x}',
by: '{\boldsymbol y}',
bz: '{\boldsymbol z}',
}
}
});
And I try to use the file (using require command) as
$$
require{boldfont}
bf=bu+bv-bw
$$
But it doesn't work, what's wrong? How to define macro and use it?
Help me, please.
require mathjax
Please post a snippet that reproduced the problem.
– Peter Krautzberger
Nov 17 '18 at 17:24
Thanks ,Peter. I attached screenshot, give me some hints.
– John
Nov 18 '18 at 1:48
A screenshot is not sufficient, I'm afraid. You'll need to post a reproducible example, ideally as a snippet. Random guess: have a look at docs.mathjax.org/en/latest/advanced/extension-writing.html
– Peter Krautzberger
Nov 19 '18 at 10:19
add a comment |
I often use vector operation, and normally vector is written by Bold font, e.g.
$$ boldsymbol x = boldsymbol a times boldsymbol b + boldsymbol c $$
which is somehow too long, so I like to define some new commands bx, ba, bb first,
$$
newcommand{bx}{boldsymbol x}
newcommand{ba}{boldsymbol a}
newcommand{bb}{boldsymbol b}
newcommand{bc}{boldsymbol c}
$$
then above equation can be written shortly as:
$$ bx = ba times bb + bc $$
Because I use these Bold fonts so often, I don't want to type them time by time, I plan to define them as macro in a file: boldfont.js , when I need to type vector, I just require boldfont.js.
I write file as follows (save the file as: /config/TeX/boldfont.js, other file (such as color.js) under the same directory):
MathJax.Hub.Config({
TeX: {
Macros: {
ba: '{\boldsymbol a}',
bb: '{\boldsymbol b}',
bc: '{\boldsymbol c}',
bd: '{\boldsymbol d}',
be: '{\boldsymbol e}',
bf: '{\boldsymbol f}',
bg: '{\boldsymbol g}',
bh: '{\boldsymbol h}',
bi: '{\boldsymbol i}',
bj: '{\boldsymbol j}',
bk: '{\boldsymbol k}',
bl: '{\boldsymbol l}',
bm: '{\boldsymbol m}',
bn: '{\boldsymbol n}',
bo: '{\boldsymbol o}',
bp: '{\boldsymbol p}',
bq: '{\boldsymbol q}',
br: '{\boldsymbol r}',
bs: '{\boldsymbol s}',
bt: '{\boldsymbol t}',
bu: '{\boldsymbol u}',
bv: '{\boldsymbol v}',
bw: '{\boldsymbol w}',
bx: '{\boldsymbol x}',
by: '{\boldsymbol y}',
bz: '{\boldsymbol z}',
}
}
});
And I try to use the file (using require command) as
$$
require{boldfont}
bf=bu+bv-bw
$$
But it doesn't work, what's wrong? How to define macro and use it?
Help me, please.
require mathjax
I often use vector operation, and normally vector is written by Bold font, e.g.
$$ boldsymbol x = boldsymbol a times boldsymbol b + boldsymbol c $$
which is somehow too long, so I like to define some new commands bx, ba, bb first,
$$
newcommand{bx}{boldsymbol x}
newcommand{ba}{boldsymbol a}
newcommand{bb}{boldsymbol b}
newcommand{bc}{boldsymbol c}
$$
then above equation can be written shortly as:
$$ bx = ba times bb + bc $$
Because I use these Bold fonts so often, I don't want to type them time by time, I plan to define them as macro in a file: boldfont.js , when I need to type vector, I just require boldfont.js.
I write file as follows (save the file as: /config/TeX/boldfont.js, other file (such as color.js) under the same directory):
MathJax.Hub.Config({
TeX: {
Macros: {
ba: '{\boldsymbol a}',
bb: '{\boldsymbol b}',
bc: '{\boldsymbol c}',
bd: '{\boldsymbol d}',
be: '{\boldsymbol e}',
bf: '{\boldsymbol f}',
bg: '{\boldsymbol g}',
bh: '{\boldsymbol h}',
bi: '{\boldsymbol i}',
bj: '{\boldsymbol j}',
bk: '{\boldsymbol k}',
bl: '{\boldsymbol l}',
bm: '{\boldsymbol m}',
bn: '{\boldsymbol n}',
bo: '{\boldsymbol o}',
bp: '{\boldsymbol p}',
bq: '{\boldsymbol q}',
br: '{\boldsymbol r}',
bs: '{\boldsymbol s}',
bt: '{\boldsymbol t}',
bu: '{\boldsymbol u}',
bv: '{\boldsymbol v}',
bw: '{\boldsymbol w}',
bx: '{\boldsymbol x}',
by: '{\boldsymbol y}',
bz: '{\boldsymbol z}',
}
}
});
And I try to use the file (using require command) as
$$
require{boldfont}
bf=bu+bv-bw
$$
But it doesn't work, what's wrong? How to define macro and use it?
Help me, please.
require mathjax
require mathjax
edited Nov 18 '18 at 1:46
John
asked Nov 17 '18 at 17:02
JohnJohn
13018
13018
Please post a snippet that reproduced the problem.
– Peter Krautzberger
Nov 17 '18 at 17:24
Thanks ,Peter. I attached screenshot, give me some hints.
– John
Nov 18 '18 at 1:48
A screenshot is not sufficient, I'm afraid. You'll need to post a reproducible example, ideally as a snippet. Random guess: have a look at docs.mathjax.org/en/latest/advanced/extension-writing.html
– Peter Krautzberger
Nov 19 '18 at 10:19
add a comment |
Please post a snippet that reproduced the problem.
– Peter Krautzberger
Nov 17 '18 at 17:24
Thanks ,Peter. I attached screenshot, give me some hints.
– John
Nov 18 '18 at 1:48
A screenshot is not sufficient, I'm afraid. You'll need to post a reproducible example, ideally as a snippet. Random guess: have a look at docs.mathjax.org/en/latest/advanced/extension-writing.html
– Peter Krautzberger
Nov 19 '18 at 10:19
Please post a snippet that reproduced the problem.
– Peter Krautzberger
Nov 17 '18 at 17:24
Please post a snippet that reproduced the problem.
– Peter Krautzberger
Nov 17 '18 at 17:24
Thanks ,Peter. I attached screenshot, give me some hints.
– John
Nov 18 '18 at 1:48
Thanks ,Peter. I attached screenshot, give me some hints.
– John
Nov 18 '18 at 1:48
A screenshot is not sufficient, I'm afraid. You'll need to post a reproducible example, ideally as a snippet. Random guess: have a look at docs.mathjax.org/en/latest/advanced/extension-writing.html
– Peter Krautzberger
Nov 19 '18 at 10:19
A screenshot is not sufficient, I'm afraid. You'll need to post a reproducible example, ideally as a snippet. Random guess: have a look at docs.mathjax.org/en/latest/advanced/extension-writing.html
– Peter Krautzberger
Nov 19 '18 at 10:19
add a comment |
1 Answer
1
active
oldest
votes
The TeX configuration block is read when the TeX input jax is first loaded, so if you call MathJax.Hub.Config()
after that, the changes you make will not be seen by the TeX input jax. So any macros you add that way will not have an effect.
Instead you should use
MathJax.InputJax.TeX.Macro('bx', '\boldsymbol{x}');
MathJax.InputJax.TeX.Macro('ba', '\boldsymbol{a}');
...
If you have a macro that takes arguments, you can add a third parameter that is the number of arguments needed. E.g.
MathJax.InputJax.TeX.Macro('bs', '\boldsymbol{#1}', 1);
The file should be stored in the MathJax/extensions/TeX
folder (not MathJax/config/TeX
), and if you call it boldfont.js
, then at the end of the file, you need to add the line
MathJax.Ajax.loadComplete('[MathJax]/extensions/TeX/boldfont.js');
With those changes, I think you should be able to get it to work. If not, check your console log for messages, and also use
MathJax.Message.Log()
to see if there are any file-load failures listed.
(This is my answer from the MathJax User's Forum where this question was cross posted).
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53353483%2fhow-to-define-and-use-macro-in-mathjax%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The TeX configuration block is read when the TeX input jax is first loaded, so if you call MathJax.Hub.Config()
after that, the changes you make will not be seen by the TeX input jax. So any macros you add that way will not have an effect.
Instead you should use
MathJax.InputJax.TeX.Macro('bx', '\boldsymbol{x}');
MathJax.InputJax.TeX.Macro('ba', '\boldsymbol{a}');
...
If you have a macro that takes arguments, you can add a third parameter that is the number of arguments needed. E.g.
MathJax.InputJax.TeX.Macro('bs', '\boldsymbol{#1}', 1);
The file should be stored in the MathJax/extensions/TeX
folder (not MathJax/config/TeX
), and if you call it boldfont.js
, then at the end of the file, you need to add the line
MathJax.Ajax.loadComplete('[MathJax]/extensions/TeX/boldfont.js');
With those changes, I think you should be able to get it to work. If not, check your console log for messages, and also use
MathJax.Message.Log()
to see if there are any file-load failures listed.
(This is my answer from the MathJax User's Forum where this question was cross posted).
add a comment |
The TeX configuration block is read when the TeX input jax is first loaded, so if you call MathJax.Hub.Config()
after that, the changes you make will not be seen by the TeX input jax. So any macros you add that way will not have an effect.
Instead you should use
MathJax.InputJax.TeX.Macro('bx', '\boldsymbol{x}');
MathJax.InputJax.TeX.Macro('ba', '\boldsymbol{a}');
...
If you have a macro that takes arguments, you can add a third parameter that is the number of arguments needed. E.g.
MathJax.InputJax.TeX.Macro('bs', '\boldsymbol{#1}', 1);
The file should be stored in the MathJax/extensions/TeX
folder (not MathJax/config/TeX
), and if you call it boldfont.js
, then at the end of the file, you need to add the line
MathJax.Ajax.loadComplete('[MathJax]/extensions/TeX/boldfont.js');
With those changes, I think you should be able to get it to work. If not, check your console log for messages, and also use
MathJax.Message.Log()
to see if there are any file-load failures listed.
(This is my answer from the MathJax User's Forum where this question was cross posted).
add a comment |
The TeX configuration block is read when the TeX input jax is first loaded, so if you call MathJax.Hub.Config()
after that, the changes you make will not be seen by the TeX input jax. So any macros you add that way will not have an effect.
Instead you should use
MathJax.InputJax.TeX.Macro('bx', '\boldsymbol{x}');
MathJax.InputJax.TeX.Macro('ba', '\boldsymbol{a}');
...
If you have a macro that takes arguments, you can add a third parameter that is the number of arguments needed. E.g.
MathJax.InputJax.TeX.Macro('bs', '\boldsymbol{#1}', 1);
The file should be stored in the MathJax/extensions/TeX
folder (not MathJax/config/TeX
), and if you call it boldfont.js
, then at the end of the file, you need to add the line
MathJax.Ajax.loadComplete('[MathJax]/extensions/TeX/boldfont.js');
With those changes, I think you should be able to get it to work. If not, check your console log for messages, and also use
MathJax.Message.Log()
to see if there are any file-load failures listed.
(This is my answer from the MathJax User's Forum where this question was cross posted).
The TeX configuration block is read when the TeX input jax is first loaded, so if you call MathJax.Hub.Config()
after that, the changes you make will not be seen by the TeX input jax. So any macros you add that way will not have an effect.
Instead you should use
MathJax.InputJax.TeX.Macro('bx', '\boldsymbol{x}');
MathJax.InputJax.TeX.Macro('ba', '\boldsymbol{a}');
...
If you have a macro that takes arguments, you can add a third parameter that is the number of arguments needed. E.g.
MathJax.InputJax.TeX.Macro('bs', '\boldsymbol{#1}', 1);
The file should be stored in the MathJax/extensions/TeX
folder (not MathJax/config/TeX
), and if you call it boldfont.js
, then at the end of the file, you need to add the line
MathJax.Ajax.loadComplete('[MathJax]/extensions/TeX/boldfont.js');
With those changes, I think you should be able to get it to work. If not, check your console log for messages, and also use
MathJax.Message.Log()
to see if there are any file-load failures listed.
(This is my answer from the MathJax User's Forum where this question was cross posted).
answered Dec 15 '18 at 19:10
Davide CervoneDavide Cervone
7,1481835
7,1481835
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53353483%2fhow-to-define-and-use-macro-in-mathjax%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please post a snippet that reproduced the problem.
– Peter Krautzberger
Nov 17 '18 at 17:24
Thanks ,Peter. I attached screenshot, give me some hints.
– John
Nov 18 '18 at 1:48
A screenshot is not sufficient, I'm afraid. You'll need to post a reproducible example, ideally as a snippet. Random guess: have a look at docs.mathjax.org/en/latest/advanced/extension-writing.html
– Peter Krautzberger
Nov 19 '18 at 10:19