GeneralLong names in \newcommand and \linebreak

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
latexmyface
Posts: 4
Joined: Wed May 21, 2008 7:02 pm

Long names in \newcommand and \linebreak

Post by latexmyface »

Hi everyone,

I'm writing this really long and annoying chemistry lab report.

I have to use horribly long names for the organic compounds we used and in order to make things easier for me I defined new commands outputting the corresponding names:

\newcommand{\compoundone}{Really-long-long-long name!!}

Now when putting \compoundone here and there that new command does what it has to: It outputs the name.
However it will not position line breaks properly. Those horribly extensive names extend into the right margins before a line break is inserted.

The major issue I think is that those organic compound names are continuous strings. So they are all one string connected via hyphens, brackets, and what not.


Does anyone have an idea?


Thanks

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Long names in \newcommand and \linebreak

Post by Stefan Kottwitz »

Hi,

can you give one example of such a big string that causes the linebreak problems? Or even a small compilable example (few lines) where it occurs? (it may even depend on fontencoding, settings and packages)

Stefan
LaTeX.org admin
latexmyface
Posts: 4
Joined: Wed May 21, 2008 7:02 pm

Long names in \newcommand and \linebreak

Post by latexmyface »

Hi,

thanks for you efforts.

Code: Select all

\documentclass[10pt,a4paper,english]{article}



\usepackage{multirow}

\usepackage{graphicx}

\usepackage{algorithmic}

\usepackage{algorithm}




\usepackage[german]{babel}



\usepackage[toc,page]{appendix}




% Line width

\usepackage{setspace}

\onehalfspacing








\usepackage{geometry}

\geometry{a4paper,left=2.5cm,right=2.5cm,top=3cm,bottom=3cm} 



%\usepackage[scaled]{uarial}

\renewcommand*\familydefault{\sfdefault}



%Tabluar cell spacing

\renewcommand\arraystretch{1.7}% (MyValue=1.0 is for standard spacing



% Row distance

\renewcommand{\baselinestretch}{1.5}



\usepackage{datetime}

\renewcommand{\dateseparator}{.}

\ddmmyyyydate



\usepackage{sectsty}

     \sectionfont{\normalsize}

   \subsectionfont{\normalsize}

   \subsubsectionfont{\normalsize} 



\usepackage{fancyhdr}



\fancyhead[RO,RE]{\today}

\fancyhead[LO,LE]{}

\fancyfoot[RO,RE]{}

\fancyfoot[CO,CE]{\thepage}

\fancyfoot[LO,LE]{}


\newcommand{\compound}{(E)-Ethyl

3-((3aR,5R,6S,6aR)-6-(\textit{tert}-butyldimethylsilyloxy)-2,2-dimethyltetrahydrofuro[2,3-d][1,3]dioxol-5-yl)acrylat}

\begin{document}





\title{XXX}

\author{XXX}

\date{\today}

\maketitle




\begin{abstract}



\end{abstract}





\pagestyle{fancy}




\section{Einleitung}



\subsection{Darstellung von \compund}

\end{document}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Long names in \newcommand and \linebreak

Post by localghost »

Try a special syntax to allow hyphenation wherever it is possible.

Code: Select all

\newcommand{\compound}{(E)-Ethyl3"=((3aR,5R,6S,6aR)"=6"=(\textit{tert}"=butyldimethylsilyloxy)"=2,2"=dimethyltetrahydrofuro[2,3"=d][1,3]dioxol"=5"=yl)acrylat}
Success can not be guaranteed.


Best regards
Thorsten
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Long names in \newcommand and \linebreak

Post by Stefan Kottwitz »

Hi,

if Thorstens solution does not work if you use it inside the preamble then place it after \begin{document}. Perhaps the shortcut "= is not working before because of babel.
Btw. you should use ngerman instead of german as option for babel.

The hyphenation may be improved even more, have a look at the
ngerman/german documentation 2.2.4 Trennhilfen fuer die automatische Silbentrennung, consider for instance the shortcut "-.

Stefan
LaTeX.org admin
latexmyface
Posts: 4
Joined: Wed May 21, 2008 7:02 pm

Re: Long names in \newcommand and \linebreak

Post by latexmyface »

Hi again German gang of latex-community.

I am using localghost's solution with Stefan's modification, i.e. I am placing the whole thing after \begin{document} with all hyphens replaced with a "=.

Works like a charm as those North American folks would say.


Thanks a lot for your help!
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Long names in \newcommand and \linebreak

Post by localghost »

I remember another modification that allows such declarations in the preamble, but only works with babel. This packages provides two commands (some kind of switches) to turn effects of special characters on or off.

Code: Select all

\documentclass[10pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage[ngerman]{babel}
\usepackage[toc,page]{appendix}

% Interline spacing
\usepackage{setspace}
\onehalfspacing

% Page geometry
\usepackage{geometry}
\geometry{
centering,
includeheadfoot,
hmargin=2.5cm,
vmargin=3cm
}

% Font settings
%\usepackage[scaled]{uarial}
\renewcommand*\familydefault{\sfdefault}

%Tabular cell spacing
\renewcommand\arraystretch{1.5}

% Date formatting
\usepackage{datetime}
\renewcommand{\dateseparator}{.}
\ddmmyyyydate

% Title formatting
\usepackage{sectsty}
\sectionfont{\normalsize}
\subsectionfont{\normalsize}
\subsubsectionfont{\normalsize}
%\allsectionsfont{\normalsize}

% Page layout
\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[RO,RE]{\today}
\fancyhead[LO,LE]{}
\fancyfoot[RO,RE]{}
\fancyfoot[CO,CE]{\thepage}
\fancyfoot[LO,LE]{}

% Declaration of compounds
\shorthandon{"}
\newcommand{\compound}{%
  (E)-Ethyl3"=((3aR,5R,6S,6aR)"=6"=(\textit{tert}"=butyldimethylsilyloxy)"=
  2,2"=dimethyltetrahydrofuro[2,3"=d][1,3]dioxol"=5"=yl)acrylat
}
\shorthandoff{"}    % May be omitted

\begin{document}
  \ldots
\end{document}
Pay special attention to the section "Declaration of compounds" in the preamble with its two additional commands. This should also work as desired.
latexmyface
Posts: 4
Joined: Wed May 21, 2008 7:02 pm

Re: Long names in \newcommand and \linebreak

Post by latexmyface »

What's the advantage of putting it in the preamble?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Long names in \newcommand and \linebreak

Post by localghost »

latexmyface wrote:What's the advantage of putting it in the preamble?
That depends on the point of view. I find it more clear to declare often used commands in the preamble, so I can find them very easy in case of need for modifications. I myself would go a step further and put these commands (if there are many of them) into an external file that is read with the \input command. That makes sure that the structure of the document is kept clear.
Post Reply