LaTeX forum ⇒ Text Formatting^ in text mode.

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

^ in text mode.

Postby Laurentius » Tue Aug 18, 2015 11:33 am

Can we redefine ^ such that, if in math mode, it behaves normally; but, if in text mode, it: (1) enters math mode; (2) does ^ w/ argument; (3) exits math mode?

Tags:

User avatar
Johannes_B
Site Moderator
Posts: 3584
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Tue Aug 18, 2015 11:40 am

No. Your favourite text editor will help you there.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

User avatar
Stefan Kottwitz
Site Admin
Posts: 8523
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Tue Aug 18, 2015 12:23 pm

You could define ^ to be an active character which works like a command, but it cannot change the source code.

As Johannes said, your editor may have an auto-completion feature which can be used. Which editor are you using?

There's also the free and open source program autohotkey, which can be used for such a purpose and for many more.

Stefan
Site admin

User avatar
cgnieder
Site Moderator
Posts: 1974
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Tue Aug 18, 2015 12:23 pm

You can make it active and then make something like this:

  1. \documentclass{article}
  2.  
  3. \begin{document}
  4.  
  5. \catcode`\^=13
  6. \newcommand*^[1]{\ensuremath{\sp{#1}}}
  7.  
  8. A^3 $A^3$
  9.  
  10. \end{document}


I have no idea if this has the potential to break anything, though. Usage on your own risk :)

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

User avatar
Stefan Kottwitz
Site Admin
Posts: 8523
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Tue Aug 18, 2015 12:30 pm

Nice, Clemens!

Another challenge would be supporting A^33, so putting in braces until the next space, punctuation, or delimiter character. :D

Stefan
Site admin

User avatar
Johannes_B
Site Moderator
Posts: 3584
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Tue Aug 18, 2015 12:44 pm

I really cannot recommend doing this, the editor is the way to go.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

User avatar
cgnieder
Site Moderator
Posts: 1974
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Wed Aug 19, 2015 7:30 pm

Stefan_K wrote:Another challenge would be supporting A^33, so putting in braces until the next space, punctuation, or delimiter character.


Probably doable if the specs (What should serve as delimiter, what shouldn't? Should category codes be taken into account?) are clear. But there are a lot of questions: should the following space be put back into the input stream? Or shouldn't it? What, if I want to typeset A^3B (and not A^{3B} or A^3 B…?)

But actually I don't think the usage would be easier then: right now the behaviour is clear the next token or brace delimited group serves as argument just like with every other LaTeX command.

Actually I can't remember when I ever wanted to use A$^{3}$ (text+math superscript) at all. Does anyone have an example where such usage makes sense?

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 7 guests