\newcommand on Physics Forum post

In summary, this person is asking how to ask questions on Physics Forums, and has been unsuccessful in finding information on how to create a command in LaTex. After some trial and error, they have successfully created a command prompt that works with MathJax. They wouldn't post the .tex file, but would rather post the text and the resulting MathJax file.
  • #1
topolosaurus
3
0
Hello, this is my first question on Physics Forums and is a question on how to ask questions.
I have been using LaTex for a while already.

I wanted to post a thread about classical field theory. I tried to use \newcommand just to make easier the typing of expressions such as:

[tex]
\frac{\partial}{\partial \left( \frac{\partial\phi}{\partial x^\mu} \right)}
[/tex]
I haven't been able to do so and I cannot find anything on \newcommand in the main How to Latex on PF guides.

I would like to implement my command as:
Code:
\newcommand{\parcial}[2]{\frac{\partial{#1}}{\partial{#2}}}

Any ideas on how to do that? Probably this has been answered before?
Is there any systematic way of instead uploading a .tex file with all the prompt and packages?
 
Physics news on Phys.org
  • #2
$$
\newcommand{\dd}[2]{\frac{\partial #1}{\partial #2}}
\dd{f}{x}
$$
Seems to be working to me.
 
  • #3
Already solved! After some trial and error I managed to put a prompt of redefined commands that seem to be working.
Besides that, is it possible to simply upload .tex files somehow? Because I want to upload part of an article I have been working on and replacing $$ and \begin{equation} to [tex] ... [/tex] is a bit tedious (but not too much though).
 
  • #4
topolosaurus said:
Besides that, is it possible to simply upload .tex files somehow? Because I want to upload part of an article I have been working on and replacing $$ and \begin{equation} to [tex] ... [/tex] is a bit tedious (but not too much though).
I'm quite sure it is currently not possible to upload ##\LaTeX##-files for verbatim use on the forum, nor when writing an "Insight", for that matter. Both use Mathjax (also see this Insight) which comes with its own set of tags to do the ##\LaTeX##-typesetting.

If you know a language that supports regular expressions (such as Python, or Perl), it is not too hard to write a script that can take a source document and output a text that is ready for pasting into a forum or WordPress post. A while ago I wrote a small script to convert ##\LaTeX##-source into WordPress + QuickLaTeX. It should be easy to adapt to work with Mathjax instead.

However, I would not post large parts of a document on PF, at least not in a single post.
 
  • Like
Likes mfb
  • #5
why would you want to post the .tex file instead of the produced pdf (let's say)?
 
  • #6
ChrisVer said:
why would you want to post the .tex file instead of the produced pdf (let's say)?
I don't think he wants to post the .tex file.

I think he wondered whether he could upload a file containing standard ##\LaTeX## (with both text and math) and then have it automatically converted to the MathJax syntax used by the forum. (All text-mode ##\LaTeX## commands - such as ordinary enumerations - should then also be converted into forum-compatible form.)
 
  • #7
In fact that would be a great feature!
 
  • #8
It seems that whatever you write in ##\LaTeX## in one set of tags, it is still valid in the others. For example, the previous ##\LaTeX## expression \dd{f}{x} ##\left(\dd{f}{x}\right)## is valid here as it was defined in post #2. But \ddd{f}{x} ##\left(\ddd{f}{x}\right)## is not defined and shows up as an error. It is however defined in this ##hidden\ \LaTeX
\newcommand{\ddd}[2]{\frac{\partial^2 #1}{\partial #2^2}}## (right-click expression and select «Show Math As -> TeX Commands») and now it shows up correctly ##\ddd{f}{x}##.

So just copy your .tex file at the beginning of your first post and it should be valid for your subsequent posts as well. I guess if the thread is spread on multiple pages, the .tex file will have to be rewritten in one early post on each page if needed.
 
  • Like
Likes jim mcnamara, Orodruin, DrClaude and 1 other person
  • #9
jack action said:
I guess if the thread is spread on multiple pages...
You might be able to just make a reply in the text box of the original page, then select the text, or click select all... then "cut" and paste the text into the reply box on a different numbered page... ?

The below text actually came from another thread...
Noisy Rhysling said:
A safer saw has my approval.
Here's a screen shot of what I'm trying to say...

Cut and Paste.JPG


Clear as mud, eh ? :oldsmile:
 
Last edited:

1. What is a \newcommand and how do I use it?

A \newcommand is a command in LaTeX that allows you to create your own custom commands for mathematical expressions, symbols, or text. To use it, you must first define the command using the \newcommand syntax, followed by the name of the command and its corresponding output. For example, \newcommand{\myvar}{x^2} will create a command named \myvar that outputs x^2 when used in your document.

2. Can I use \newcommand to create my own units in physics?

Yes, you can use \newcommand to create your own units in LaTeX. For example, you can define a command for the unit "meter per second" as \newcommand{\ms}{\mathrm{m/s}}. This will allow you to easily type \ms in your document instead of having to write out the entire unit every time.

3. Is it possible to use \newcommand to define multiple variables at once?

Yes, you can use \newcommand to define multiple variables at once. To do this, you can use the \def syntax instead of \newcommand. For example, \def\vx{\mathbf{x}}\def\vy{\mathbf{y}} will define two commands, \vx and \vy, that output the bolded versions of x and y, respectively.

4. How can I create a \newcommand for a complex mathematical expression?

To create a \newcommand for a complex mathematical expression, you can use the \ensuremath command. This allows you to use both text and math symbols in your command, without having to switch back and forth between math mode and text mode. For example, \newcommand{\myeq}{\ensuremath{E = mc^2}} will create a command that outputs the famous equation E = mc^2 when used in your document.

5. Can I use \newcommand in conjunction with other LaTeX packages?

Yes, you can use \newcommand in conjunction with other LaTeX packages. However, it is important to note that some packages may already have predefined commands with the same name as your \newcommand, which can lead to conflicts. In these cases, it is best to choose a different name for your command or use the \renewcommand syntax instead.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
298
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
23
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
39
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
Back
Top