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.

My MWE below produces the following in the \jobname.ypos.txt file:

{1}{1}{1}{F}{0}
{1}{1}{1}{L}{0}
{1}{1}{2}{F}{0}
{1}{1}{2}{L}{0}
{1}{1}{3}{F}{0}
{1}{1}{3}{L}{0}

Where the bunch of zeros at the end are supposed to be the y-pos coordinates coming from \pdfsavepos and pdflastypos.

I'm obviously missing something fundamental here, but can't figure it out.

MWE:

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

\defaultfontfeatures{Mapping=tex-text}
\setmainfont{Times New Roman}

% Write the position to file.
% #1 is the book number
% #2 is the chapter number
% #3 is the verse number
% #4 is the position, first (F) or last (L), to be saved
\def\msec@write@lines#1#2#3#4{%
    \pdfsavepos%
    \immediate\write\yposoutputfile{%
    \string{#1\string}%
    \string{#2\string}%
        \string{#3\string}%
    \string{#4\string}%
        \string{\the\pdflastypos\string}%
    }%
}

\begin{document}
\newwrite\yposoutputfile%
\immediate\openout\yposoutputfile=\jobname.ypos.txt%

\LARGE{1} \msec@write@lines{1}{1}{1}{F} LIBRO de la generación de Jesucristo, hijo de David, hijo de Abraham. \msec@write@lines{1}{1}{1}{L}
\msec@write@lines{1}{1}{2}{F} \textbf{2}~Abraham engendró á Isaac: é Isaac engendró á Jacob: y Jacob engendró á Judas y á sus hermanos:\msec@write@lines{1}{1}{2}{L}
\msec@write@lines{1}{1}{3}{F} \textbf{3}~Y Judas engendró de Thamar á Phares y á Zara: y Phares engendró á Esrom: y Esrom engendró á Aram:\msec@write@lines{1}{1}{3}{L}

\immediate\closeout\yposoutputfile%
\end{document}
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

The position is known at shipout time, thus you cannot use \immediate\write. Without \immediate

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

\defaultfontfeatures{Mapping=tex-text}
\setmainfont{Times New Roman}

% Write the position to file.
% #1 is the book number
% #2 is the chapter number
% #3 is the verse number
% #4 is the position, first (F) or last (L), to be saved
\def\msec@write@lines#1#2#3#4{%
    \pdfsavepos%
    \write\yposoutputfile{%
    \string{#1\string}%
    \string{#2\string}%
        \string{#3\string}%
    \string{#4\string}%
        \string{\the\pdflastypos\string}%
    }%
}

\begin{document}
\newwrite\yposoutputfile%
\openout\yposoutputfile=\jobname.ypos.txt%

\LARGE{1} \msec@write@lines{1}{1}{1}{F} LIBRO de la generación de Jesucristo, hijo de David, hijo de Abraham. \msec@write@lines{1}{1}{1}{L}
\msec@write@lines{1}{1}{2}{F} \textbf{2}~Abraham engendró á Isaac: é Isaac engendró á Jacob: y Jacob engendró á Judas y á sus hermanos:\msec@write@lines{1}{1}{2}{L}
\msec@write@lines{1}{1}{3}{F} \textbf{3}~Y Judas engendró de Thamar á Phares y á Zara: y Phares engendró á Esrom: y Esrom engendró á Aram:\msec@write@lines{1}{1}{3}{L}

\closeout\yposoutputfile%
\end{document}

the file test.ypos.tex contains:

{1}{1}{1}{F}{29794429}
{1}{1}{1}{L}{26910845}
{1}{1}{2}{F}{26910845}
{1}{1}{2}{L}{24027261}
{1}{1}{3}{F}{24027261}
{1}{1}{3}{L}{19701885}
share|improve this answer
    
I see, thanks. I have adapted the solution from somewhere else and misunderstood the usage of immediate in this context. –  McGafter Dec 20 '12 at 16:08
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.