Loading ...
Sorry, an error occurred while loading the content.

vertical alignment in sidebar

Expand Messages
  • laborde
    Hello, I use XEP, and I have documents consisting of narrative text, and some paragraphs contain terms that must be defined in the side margins or sidebar. I
    Message 1 of 8 , Apr 13, 2006
    • 0 Attachment
      Hello,
      I use XEP, and I have documents consisting of narrative text, and
      some paragraphs contain terms that must be defined in the side margins
      or sidebar. I have accomplished this by using floats, as explained
      below, but the problem is that I cannot control the vertical alignment
      of the definitions in the sidebar. (By "sidebar" I mean in the margin, a
      true sidebar, another column, whatever works.) As is, my stylesheet
      keeps each definition in line with its containing paragraph. But what I
      really need is for each definition to appear in the sidebar on the same
      line as it occurs in the paragraph. For instance, if a very long
      paragraph contains <term>word1</term> in the first line and
      <term>word2</term> in the last line, then the definition of 'word1'
      should appear in the sidebar and be in vertical alignment with the first
      line of the paragraph, and the definition of 'word2' should line up with
      the last line of the paragraph. But is that possible? Unlike a block,
      there is no "line" area, right? Is there any way to do this, maybe with
      something besides floats?
      I do have control over the XML, so I can make some changes there if
      that will help. (But I can't change the content, so there will always be
      elements that occur between paragraphs, which threw me when I tried to
      do this by using tables.)
      Any help would be greatly appreciated as I have other projects that
      will require the same format.

      Thank you,
      Susan LaBorde

      The XML looks basically like this:
      <div>
      <p><gap/> First sentence of paragraph with a <term
      sameAs="word1">word1</term> that must be defined in the sidebar or
      margin. Paragraph may contain few, many or no terms to be defined. A
      very long paragraph may have only one term to be defined, and this <term
      sameAs="word2">word2</term> might occur in the last line of the
      paragraph.</p>
      <damage/>
      <symbol/>
      <p>...</p>
      </div>

      Definitions for the terms are in a separate XML document that looks like
      this (but if it would matter I can move them to occur inline next to
      their corresponding <term> elements):
      <glossary>
      <item id="word1">
      <name>word1</name>
      <gloss>definition of word1</gloss>
      </item>
      </glossary>

      As for the XSL, I've simplified this as well as I know how, and here are
      the page sequence and the templates for the elements "p" "term" and "item":

      <fo:page-sequence master-reference="standard" format="1"
      force-page-count="no-force" initial-page-number="1">
      <fo:flow flow-name="xsl-region-body">
      <fo:block>
      <xsl:apply-templates select="body/div"/><!--I
      believe that here I *must* select div in order that the elements that
      occur between paragraphs be processed in correct document order.-->
      </fo:block>
      </fo:flow>
      </fo:page-sequence>

      <xsl:template match="p">
      <fo:block widows="2" orphans="2" intrusion-displace="none"
      margin-right="20%">
      <xsl:apply-templates select=".//term[1]" mode="sidebar"/>
      <xsl:apply-templates
      select="node()[not(self::text()[following-sibling::node()[1]/self::gap[@extent='words'][not(following-sibling::node()[normalize-space()])]
      or following-sibling::node()[1]/self::gap[@extent='eos']])]"/><!--Sorry,
      lots of other stuff going on here with gap elements.-->
      <xsl:if test="following-sibling::*[1][self::pb]">
      <fo:inline><xsl:text> [P/] </xsl:text></fo:inline>
      </xsl:if>
      </fo:block>
      </xsl:template>

      <xsl:template match="term" mode="sidebar">
      <fo:float float="end">
      <fo:block-container inline-progression-dimension="14em"
      start-indent="1em" end-indent="-20em">
      <fo:block>
      <xsl:apply-templates
      select="//item[@id=current()/@sameAs]" mode="sidebar"/>
      </fo:block>
      <xsl:if test="following-sibling::term">
      <fo:block><fo:leader/></fo:block>
      <xsl:for-each select="following-sibling::term">
      <fo:block>
      <xsl:apply-templates
      select="//item[@id=current()/@sameAs]" mode="sidebar"/>
      </fo:block>
      <fo:block><fo:leader/></fo:block>
      </xsl:for-each>
      </xsl:if>
      </fo:block-container>
      </fo:float>
      </xsl:template>

      <xsl:template match="item" mode="sidebar">
      <xsl:apply-templates select="name"/>
      <xsl:apply-templates select="gloss"/>
      </xsl:template>
    • Eliot Kimber
      ... The anchor for the float should occur immediately before the word you want it vertically aligned with--that s the only control you have in FO for vertical
      Message 2 of 8 , Apr 13, 2006
      • 0 Attachment
        laborde wrote:
        > Any help would be greatly appreciated as I have other projects that
        > will require the same format.

        The anchor for the float should occur immediately before the word you
        want it vertically aligned with--that's the only control you have in FO
        for vertical alignment.

        Cheers,

        E.
        --
        W. Eliot Kimber
        Professional Services
        Innodata Isogen
        9390 Research Blvd, #410
        Austin, TX 78759
        (512) 372-8841

        ekimber@...
        www.innodata-isogen.com
      • laborde
        ... Thank you. I have it working now, almost. I believe inheritance is tripping me up. The lines in paragraphs are double-spaced (line-height= 200%). In the
        Message 3 of 8 , Apr 14, 2006
        • 0 Attachment
          Eliot Kimber wrote:
          > The anchor for the float should occur immediately before the word you
          > want it vertically aligned with--that's the only control you have in FO
          > for vertical alignment.
          >
          Thank you. I have it working now, almost. I believe inheritance is
          tripping me up. The lines in paragraphs are double-spaced
          (line-height="200%). In the sidebar, any definitions that run more than
          one line should be single-spaced. Am I correct that the float is
          inheriting its line-height from its containing area? I've tried
          everything but can't seem to override that. I have:

          <xsl:template match="p">
          <fo:block font-family="Times" font-size="12pt" line-height="200%"
          text-indent="2em" line-height-shift-adjustment="disregard-shifts"
          widows="2" orphans="2" intrusion-displace="none" margin-right="20%">
          <xsl:apply-templates/>
          </fo:block>
          </xsl:template>

          <xsl:template match="term">
          <fo:inline>
          <xsl:apply-templates/>
          <fo:float float="end">
          <fo:block-container inline-progression-dimension="14em"
          font-family="Helvetica" font-size="8pt" font-style="italic"
          start-indent="1em" end-indent="-20em">
          <xsl:for-each select="//item[@id=current()/@sameAs]">
          <fo:block>
          <xsl:apply-templates select="name"/>
          <xsl:text>: </xsl:text>
          <xsl:apply-templates select="gloss"/>
          </fo:block>
          </xsl:for-each>
          </fo:block-container>
          </fo:float>
          </fo:inline>
          </xsl:template>

          In the template matching "term", can I specify line-height so that text
          in floats will be single-spaced? If so, where? And what would be the
          value for line-height in the floats--25%? Or less because the font-size
          is smaller?
          I appreciate your help.
          Susan LaBorde
        • Eliot Kimber
          ... NOTE: it s easier to see what s happening if you provide the generated FO rather than the generating templates--that way we can see exactly what s
          Message 4 of 8 , Apr 14, 2006
          • 0 Attachment
            laborde wrote:
            > In the template matching "term", can I specify line-height so that text
            > in floats will be single-spaced? If so, where? And what would be the
            > value for line-height in the floats--25%? Or less because the font-size
            > is smaller?

            NOTE: it's easier to see what's happening if you provide the generated
            FO rather than the generating templates--that way we can see exactly
            what's happening.

            You can specify line-height="120%" (or whatever value is appropriate)
            for the sidebar on the float or the block-container w/in the float--it
            doesn't matter as it's an inherited property.

            Line height specified as a percentage is relative to the font size of
            the text it applies to, in this case the font size of the text in the
            sidebar--it's not applied to the line height of the outer context.

            So assuming you want normal "8 on 10" leading you would specify a line
            height of 120% (or a line height of 10pt--it means about the the same
            thing if the base font size is 8pt (it would be exactly the same thing
            if the font size was 10pt--20% of 8pt is a little less than 2 points so
            the result is more like 8 on 9.8 or something).

            Note that this same inheritance issue applies to footnotes as
            well--footnote areas inherit their properties from the footnote anchor's
            context.

            Cheers,

            Eliot
            --
            W. Eliot Kimber
            Professional Services
            Innodata Isogen
            9390 Research Blvd, #410
            Austin, TX 78759
            (512) 372-8841

            ekimber@...
            www.innodata-isogen.com
          • laborde
            ... Okay, sorry. Below I have pasted in the generated FO. I *think* I am doing exactly what you re telling me, but apparently not because it still isn t
            Message 5 of 8 , Apr 14, 2006
            • 0 Attachment
              Eliot Kimber wrote:
              > NOTE: it's easier to see what's happening if you provide the generated
              > FO rather than the generating templates--that way we can see exactly
              > what's happening.
              >
              Okay, sorry. Below I have pasted in the generated FO. I *think* I am
              doing exactly what you're telling me, but apparently not because it
              still isn't working. Here, the definition for first-term runs 3 lines in
              the sidebar, and these lines are double spaced with same spacing between
              lines as in paragraphs. (Not to mention that the second and third lines
              of first definition are printing on top of the second definition.)
              Thanks,
              Susan

              <fo:block font-family="Times, Symbol, Helvetica" font-size="12pt"
              line-height="200%"
              text-indent="2em"
              line-height-shift-adjustment="disregard-shifts" widows="2" orphans="2"
              intrusion-displace="none"
              margin-right="20%"><fo:inline keep-together.within-line="always"
              > . . . </fo:inline> here begins first line of
              paragraph with
              <fo:inline>first-term<fo:float float="end"
              line-height="10pt">
              <fo:block-container
              inline-progression-dimension="14em" font-family="Helvetica"
              font-size="8pt" font-style="italic"
              start-indent="1em" end-indent="-20em">
              <fo:block>first-term: First-term with a
              definition that runs longer than one
              line</fo:block>
              </fo:block-container>
              </fo:float></fo:inline> to be defined in
              sidebar. Next sentence contains
              <fo:inline>second-term<fo:float float="end"
              line-height="10pt">
              <fo:block-container
              inline-progression-dimension="14em" font-family="Helvetica"
              font-size="8pt" font-style="italic"
              start-indent="1em" end-indent="-20em">
              <fo:block>second-term: Second-term
              definition</fo:block>
              </fo:block-container>
              </fo:float></fo:inline> to be defined in
              sidebar. Last sentence contains
              <fo:inline>third-term<fo:float float="end"
              line-height="10pt">
              <fo:block-container
              inline-progression-dimension="14em" font-family="Helvetica"
              font-size="8pt" font-style="italic"
              start-indent="1em" end-indent="-20em">
              <fo:block>third-term: Third-term
              definition</fo:block>
              </fo:block-container>
              </fo:float></fo:inline> to be defined in
              sidebar.</fo:block>
            • Eliot Kimber
              ... When I test your example with XSL Formatter V3 or XEP V4 the line height in the floats is as expected, so it looks like you re seeing a bug in your FO
              Message 6 of 8 , Apr 14, 2006
              • 0 Attachment
                laborde wrote:
                > Okay, sorry. Below I have pasted in the generated FO. I *think* I am
                > doing exactly what you're telling me, but apparently not because it
                > still isn't working. Here, the definition for first-term runs 3 lines in
                > the sidebar, and these lines are double spaced with same spacing between
                > lines as in paragraphs. (Not to mention that the second and third lines
                > of first definition are printing on top of the second definition.)

                When I test your example with XSL Formatter V3 or XEP V4 the line height
                in the floats is as expected, so it looks like you're seeing a bug in
                your FO implementation. You can try putting the property on the
                block-container instead of the float (which is probably the better place
                for it anyway).

                However, in testing this I noticed that unless the float was the first
                thing in the containing block that both XSL Formatter and XEP aligned
                the float with the top of the *next* line.

                I'm not sure why this is the case--I looked over the relevant stuff in
                the XSL and CSS specs and didn't see anything that appeared to obviously
                require this behavior but since both of them do it it's probably correct
                per the spec.

                I was able to put a negative space-before on the block container and
                pull it up to the start of the line I wanted, i.e.:

                space-before="-24pt"
                space-before.conditionality="retain"

                You need to set the conditionality because by default space before is
                conditional and the block container in the side float is the first thing
                in its containing reference area and therefore its space before would be
                discarded by default.

                The 24pt value is 200% of 12pt.

                Cheers,

                E.
                --
                W. Eliot Kimber
                Professional Services
                Innodata Isogen
                9390 Research Blvd, #410
                Austin, TX 78759
                (512) 372-8841

                ekimber@...
                www.innodata-isogen.com
              • laborde
                ... I tried but with no luck, and I m using XEP V4, so the bug has to be me. I apologize. I ve stripped my test files to bare bones, but I must have left
                Message 7 of 8 , Apr 14, 2006
                • 0 Attachment
                  Eliot Kimber wrote:
                  > When I test your example with XSL Formatter V3 or XEP V4 the line height
                  > in the floats is as expected, so it looks like you're seeing a bug in
                  > your FO implementation. You can try putting the property on the
                  > block-container instead of the float (which is probably the better place
                  > for it anyway).
                  >
                  I tried but with no luck, and I'm using XEP V4, so the bug has to be
                  me. I apologize. I've stripped my test files to bare bones, but I must
                  have left something that is interfering. I'll start from scratch and
                  find it. But I'm very glad you tested this anyway because....
                  > However, in testing this I noticed that unless the float was the first
                  > thing in the containing block that both XSL Formatter and XEP aligned
                  > the float with the top of the *next* line.
                  >
                  Yes, and I thought that was getting out of line because of the whole
                  other line-height issue. I would never have figured out how to fix this.
                  Your solution works perfectly. Thank you!
                  > You need to set the conditionality because by default space before is
                  > conditional and the block container in the side float is the first thing
                  > in its containing reference area and therefore its space before would be
                  > discarded by default.
                  I didn't know and am very glad to learn that. Thanks so much for
                  *all* your help.
                  Susan
                • laborde
                  Elliot, I got it! I was using , which caused the side float text to be double-spaced exactly like the body paragraph text. But the other problem was
                  Message 8 of 8 , Apr 17, 2006
                  • 0 Attachment
                    Elliot, I got it! I was using <fo:inline>, which caused the side float
                    text to be double-spaced exactly like the body paragraph text. But the
                    other problem was that when 3 or more <term>s occur in one line, the
                    side float definitions printed on top of each other. After reading your
                    explanation, I realized that besides using the negative value for
                    "space-before" to pull up the definition to the correct line, I then
                    have to use a larger, positive, "space-after" value--and set the
                    conditionality there too--to keep the definitions from running over each
                    other. Until you told me, I didn't know about space getting discarded
                    by default. Now all the spacing and alignment is perfect. Again, my
                    sincere thanks!
                    Susan

                    ...maybe this is a no-brainer to everyone else, but in case it's useful
                    to anyone, here's what I ended up with:

                    <xsl:template match="term">
                    <xsl:apply-templates/>
                    <fo:float float="end" clear="end">
                    <fo:block-container inline-progression-dimension="14em"
                    font-family="Helvetica" font-size="8pt" font-style="italic"
                    start-indent="1em" end-indent="-20em" line-height="8pt"
                    space-before="-16pt" space-before.conditionality="retain"
                    space-after="21pt" space-after.conditionality="retain">
                    <fo:block>
                    <xsl:for-each select="//item[@id=current()/@sameAs]">
                    <xsl:apply-templates select="name"/>

                    <xsl:apply-templates select="gloss"/>

                    </xsl:for-each>
                    </fo:block>
                    </fo:block-container>
                    </fo:float>
                    </xsl:template>
                  Your message has been successfully submitted and would be delivered to recipients shortly.