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.

I want to insert a custom space at a given point. But am not sure how to implement it in the following MWE (needs to run in XeLaTeX).

\documentclass[pagesize=pdftex, fontsize=10]{scrbook}
\usepackage[paperwidth=11.2cm, paperheight=17.4cm, top=1.6cm,bottom=1cm, left=1cm, right=1cm]{geometry}
\usepackage{calc}

\begin{document}
\newlength\myspace
\setlength{\myspace}{\widthof{\normalsize{Help my of ek help myself.}}}
\showthe\myspace
\def\text{Text mooooved over here.}
\edef\abc{\text}
\abc
\end{document}

This is what I've tried but it doesn't work. Since the \abc is actually defined by edef outside in a .sty. file i can't add the \hspace immediately in front of the \abc as it would break the rest of my rather complex document.

\documentclass[pagesize=pdftex, fontsize=10]{scrbook}
\usepackage[paperwidth=11.2cm, paperheight=17.4cm, top=1.6cm,bottom=1cm, left=1cm, right=1cm]{geometry}
\usepackage{calc}

\begin{document}
\newlength\myspace
\setlength{\myspace}{\widthof{\normalsize{Help my of ek help myself.}}}
\showthe\myspace
\def\text{Text mooooved over here.}
\edef\abc{\hspace{\myspace}\text}
\abc
\end{document}
share|improve this question
    
\leavevmode\hphantom{\normalsize Help my...} –  egreg Aug 19 '13 at 9:54
    
There does not appear to be any dependency on xetex in either the question or example code. –  David Carlisle Aug 19 '13 at 9:56
    
The solution where this will be implemented will be run in XeLaTeX. –  McGafter Aug 19 '13 at 10:02

2 Answers 2

up vote 4 down vote accepted

You should not use \edef in a latex document, it is quite likely to break any commands in its argument, use \def or better \newcommand.

The reason the \hspace is not working is that white space is discarded at the beginning of a line: use \hspace*{\myspace} where the * preserves the space. Note that as it is the beginning of a paragraph you will also get paragraph indentation.

share|improve this answer

Following David Carlisle's answer this is the working end result.

\documentclass[pagesize=pdftex, fontsize=10]{scrbook}
\usepackage[paperwidth=11.2cm, paperheight=17.4cm, top=1.6cm,bottom=1cm, left=1cm, right=1cm]{geometry}
\usepackage{calc}

\begin{document}
\newlength\myspace
\setlength{\myspace}{\widthof{\normalsize{Help my of ek help myself.}}}
\showthe\myspace
\def\text{Text mooooved over here.}
\newcommand{\abcd}{%
    \hspace*{\myspace}\text
}
\abcd
\end{document}
share|improve this answer
1  
You need \newcommand{\abcd}{% or you will get a space that is too large by one inter-word space (if you ever use this command other than teh beginning of a line) –  David Carlisle Aug 19 '13 at 11:57

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.