Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When I'm editing the source in TeXShop, I often find that I want to remove emphasis from a word or phrase. But deleting the \emph from the beginning of the word and the {} surrounding it is a bit more annoying than I would like it to be.

I suppose what I'm looking for is a script that I can execute at the start of a command (like \emph) that will scan left-to-right and delete everything except for the text between the curly braces (i.e., that will delete the "\emph", the "{", and the "}")

Something that would take me from

This is \emph{emphasized} text 

to

This is emphasized text 

In the code itself.

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

Not a TeX solution, but you can use a regular expression, for example in vim:

:%s/\\emph{\([^}]*\)}/\1/g

Caveats: doesn't remove inner \emph's (\emph{foo \emph{bar} baz}), nor if the \emph spans multiple lines. (Feel free to comment for improvements!)

share|improve this answer
    
After a bit of googling, it seems that applescript doesn't support regular expressions (and I think TeXShop only supports applescripts though I really can't be sure, all of this stuff is VERY new for me). Is there a way to modify this into something applescript compatible that you know of? The standard fix seems to be to use shell commands (cf. erik.arvedson.se/2009/08/using-regular-expressions-in.html) Is this something you could help with? –  Dennis Aug 23 '12 at 8:08
1  
@Dennis: Yes, you can use regular expressions with for example the command line utility sed, where the above expression would be the same except the first %. So, for example: sed 's/\\emph{\([^}]*\)}/\1/g' name-of-your-file.tex which would output the input after sed has made its changes (so you could forward the output with sed '....' file.tex > file_after_sed.tex for example). The same caveats apply, though. –  morbusg Aug 23 '12 at 8:58
add comment

If I understood you correctly you want something like this:

\documentclass{article}

% \disable takes two arguments and only uses the second
\makeatletter
\let\disable\@secondoftwo
\makeatother

\begin{document}

This is \emph{emphasized} text

This is \disable\emph{emphasized} text

\end{document}
share|improve this answer
    
That certainly achieves the effect. What I was really looking for was a macro or script or something that would actually remove the "\emph", the "{", and the "}" from my source. Something that would take me from This is \emph{emphasized} text to This is emphasized text In the code itself. I might be asking for something very difficult or impossible, though. At any rate, with a key binding your suggestion would be just about as effective and have wider applicability. Do you understand my question, though? I apologize for asking such an unclear question. –  Dennis Aug 23 '12 at 7:16
    
I guess it should be doable to write a script that removes all \emph's (including the braces) from the source but that's a task for someone else than me. –  cgnieder Aug 23 '12 at 7:30
    
Ok, thanks for the help. –  Dennis Aug 23 '12 at 7:31
add comment

If the same modifications must be made for all the \emph command in large documents or some big parts, I suggest you do not touch the \emph command at all, but redefine the command (in the preamble or in the body document). The main advantage is that you can easily switch between styles without touch each word emphasized. The MWE:

\documentclass{article}
\begin{document}
% Normal behaviour  
normal text \emph{emphasis text} \par
% Emphasis out
\renewcommand{\emph}[1]{#1}
normal text \emph{emphasis text} \par
% Emphasis become bold text
\renewcommand{\emph}[1]{\textbf{#1}} 
normal text \emph{emphasis text} \par
% Emphasis become underlined text
\renewcommand{\emph}[1]{\underline{#1}}
normal text \emph{emphasis text} \par
\end{document}

emph

share|improve this answer
    
This is very useful (hence the upvote) but not quite what I was looking for. I'm looking more for a way to speed up the editing process by removing a single unwanted emphasis from a word or phrase. I suppose what I'm looking for is something like a macro that I can execute at the start of a command (like \emph) that will scan left-to-right and delete everything except for the text between the curly braces (i.e., that will delete the "\emph", the "{", and the "}"). –  Dennis Aug 23 '12 at 4:20
    
Are you looking for a text editor with the ability to record and execute macros (as Nedit for Linux and Notepad++ in Windows) or a LaTeX macro? For the first see en.wikipedia.org/wiki/Comparison_of_text_editors –  Fran Aug 23 '12 at 8:09
    
Sorry, my original question was a bit confused. It seems that a script might be the fix for me. Morsbug's answer seems to have the solution but I can't be sure until I figure out how to implement it as an applescript. –  Dennis Aug 23 '12 at 8:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.