Text Formattingnewcommand parsed output?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
ishdhand
Posts: 6
Joined: Tue Sep 04, 2012 9:07 pm

newcommand parsed output?

Post by ishdhand »

I use the following:

Code: Select all

\newcommand{\ket}[1]{\left| #1 \right>} % for Dirac bras
instead of typing

Code: Select all

\left| ket-text \right>
every time.

But, for some purpose, I want my tex file in the format with the replaced commands; i.e. tex code that I would have written had I not known about \newcommand at all.

Is there some way to obtain this processed tex code?


Thanks a lot!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

newcommand parsed output?

Post by cgnieder »

Hi ishdhand,

Welcome to the LaTeX community.

I must confess I do not understand at all what you want? Do you want to automatically replace all appearances of \ket{bla} in your source with \left|bla\right>? I guess it's possible to right a shell script for this but that is not my field of expertise (meaning I have never done that myself).

BTW: there's the braket package for, well, bras, kets and brakets.

Regards
site moderator & package author
ishdhand
Posts: 6
Joined: Tue Sep 04, 2012 9:07 pm

newcommand parsed output?

Post by ishdhand »

Yes, that is what I have in mind: I want to automatically replace all appearances of \ket{bla} in your source with \left|bla\right>. Is there a way to do this?

ps: Thanks for the information about the braket package.
Last edited by cgnieder on Tue Sep 04, 2012 9:47 pm, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: newcommand parsed output?

Post by Stefan Kottwitz »

That's not a LaTeX topic, it's just text replacement. You can do it by using editor features, by processing the file by sed, perl, ... LaTeX doesn't manipulate your source file. It does macro processing and expansion naturally, so I think normally it's not needed with LaTeX to process the source file for replacement before compiling.

Stefan
LaTeX.org admin
ishdhand
Posts: 6
Joined: Tue Sep 04, 2012 9:07 pm

Re: newcommand parsed output?

Post by ishdhand »

Clarification:

I want to automatically replace all appearances of <my input to new-command eg.\ket{bla}> in your source with <the replaced code (as a result of newcommand) eg.\left|bla\right>)

Is there a way to do this?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

newcommand parsed output?

Post by Stefan Kottwitz »

So the source file will be changed, so that there's no \ket{bla} any more but just the replacement?

Stefan
LaTeX.org admin
ishdhand
Posts: 6
Joined: Tue Sep 04, 2012 9:07 pm

Re: newcommand parsed output?

Post by ishdhand »

Yes.
It would be great if I can somehow get the 'final' source file, in which all the occurrences of the old commands are replaced as I have described in the newcommand. Is there an easy way to do this?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

newcommand parsed output?

Post by Stefan Kottwitz »

Sounds like a simple string replacement, which could be done with sed and other tools. But in consequence any contained macro should be expanded and replaces as well.

Since LaTeX does exactly that automatically during the compilation, why do you want to modify the source? Isn't the expansion for the output sufficient? Is there a specific reason? Is \newcommand not allowed for you? LaTeX is a macro language based on macro defitions. Forbidding that is strange.

Stefan
LaTeX.org admin
ishdhand
Posts: 6
Joined: Tue Sep 04, 2012 9:07 pm

Re: newcommand parsed output?

Post by ishdhand »

I and my friends have lengthy (lecture and reading)notes which make extensive use of newcommand. I wanted to convert those docs to wordpress to make them public and collaborative. We found a tool (http://lucatrevisan.wordpress.com/latex-to-wordpress/) that converts latex to wordpress code, but as an input to this tool, I need the replaced version of out tex source. I understand that latex does just this same replacement during complication and was, hence, wondering if there was some way to obtain the 'intermediate (partly compiled) code'.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

newcommand parsed output?

Post by Stefan Kottwitz »

WinEdt provides such a feature: uncommand.

Furtheremore, there's the de-macro package.

Stefan
LaTeX.org admin
Post Reply