Text FormattingHyphenation issue

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
AliceWonder
Posts: 28
Joined: Wed Oct 31, 2012 12:04 am

Hyphenation issue

Post by AliceWonder »

Hello,
I have the following defined in my tex

Code: Select all

\hyphenation{Java-Script}
%
\newcounter{jscount}
\newcommand{\JS}{\addtocounter{jscount}{1}JavaScript\ifthenelse{\equal{\value{jscount}}{1}}{\textsuperscript{\textregistered}}{}}
The macro is defined so that the first time JavaScript is used, the appropriation trademark symbol is added.

Unfortunately the first occurrence is a place where the hyphenation should take place. It seems that with the registered trademark symbol, the hyphenation macro doesn't recognize it and it flows into the margin.

If I increment the counter before the use, then the mark isn't there and the hyphenation works.

I'm guessing there is a better way to define my \JS{} macro so that the addition of the registered trademark does not prevent the hyphenation?
Last edited by cgnieder on Sun Nov 11, 2012 2:25 pm, edited 1 time in total.

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

Hyphenation issue

Post by cgnieder »

Well, as soon as you append the symbol it isn't the same word any more as far as LaTeX is concerned. I would suggest another definition:

Code: Select all

\documentclass{article}
\usepackage{showframe}% to show the page layout

\newcommand*\JS{Java\-Script\textsuperscript{\textregistered}\gdef\JS{Java\-Script}}

\begin{document}

Text Text Text Text Text Text Text Text Text Text Text Text Text \JS{} Text Text
\JS{} Text Text.

\end{document}
This definition 1) sets explicit hyphenation points using \- and 2) redefines itself on first usage so no counter is needed.

Regards
site moderator & package author
AliceWonder
Posts: 28
Joined: Wed Oct 31, 2012 12:04 am

Re: Hyphenation issue

Post by AliceWonder »

Thanks for the redefine tip!
Post Reply