General ⇒ Long names in \newcommand and \linebreak
-
- Posts: 4
- Joined: Wed May 21, 2008 7:02 pm
Long names in \newcommand and \linebreak
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
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Stefan Kottwitz
- Site Admin
- Posts: 10360
- Joined: Mon Mar 10, 2008 9:44 pm
Re: Long names in \newcommand and \linebreak
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
-
- Posts: 4
- Joined: Wed May 21, 2008 7:02 pm
Long names in \newcommand and \linebreak
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}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Long names in \newcommand and \linebreak
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}
Best regards
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
- Stefan Kottwitz
- Site Admin
- Posts: 10360
- Joined: Mon Mar 10, 2008 9:44 pm
Long names in \newcommand and \linebreak
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
-
- Posts: 4
- Joined: Wed May 21, 2008 7:02 pm
Re: Long names in \newcommand and \linebreak
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!
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Long names in \newcommand and \linebreak
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}
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 4
- Joined: Wed May 21, 2008 7:02 pm
Re: Long names in \newcommand and \linebreak
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Long names in \newcommand and \linebreak
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.latexmyface wrote:What's the advantage of putting it in the preamble?
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10