Superscripts do not work in Code Span

A variety of errors occur when I try to use superscripts in Code Span. I will try to paste examples here, but I don’t know if it will work. I don’t see any way to say “this is plain text, don’t try to interpret it as something.”

No Style: 102.

Code Span: 10^2^, 2.2x10<sup>-26</sup>.

  • A double is a 64-bit “real” (floating point) number in the range plus or minus 4.9406564584124654x10<sup>-324 to 1.7976931348623157x10<sup>308.
  • I can use Sigil to fix the errors, but this is definitely a bug that I would like to see fixed.

    I do agree that this output is buggy, as it is producing invalid HTML.

    What is the result that you are looking for however? You mention fixing it in Sigil, what HTML would you use to display this? When I think of treating something as plain-text, I take that literally—stripped of all formatting—like you’d want the result to be 102, 2.2x10-26, but you probably don’t mean that.

    If you do want <sup>-25</sup> for example, something you could do is create a character styled called “Raw HTML”, which the default Ebook compile format has a matching style for, that does just what you’d expect for the most part. What you may not expect otherwise is that you can use some Markdown in these as well, so your example (slightly modified to demonstrate subscripts) could be typed in as 10^2^, 2.2.x10~-26 and it would come out as “102, 2.2x10-26”. (And as you can see from that example, that’s what Scrivener is trying to do, but not quite correctly evidently.)

    Another question would be whether you really need this to be a code span, or if just changing the font to monospace is good enough. If so, then I’d consider using a differently named style for these strings, saving it as a character style that preserves the font family, and optionally the font size, using Courier New to ensure that comes through as monospace in the reader (the actual font it uses may be different). Then it will just be treated as formatted text.

    So I’d say you have a few options there, all better than editing after compiling in my opinion.

    Hi Amber. Thanks for the clue, but I’m having trouble figuring out how to follow it.

    By “plain text” I just meant that I didn’t know what this message area in the forum would do with the HTML I entered. Yes, what I want is the sup tag before and the /sup tag after some numbers. I’ve read what the manual says about raw HTML, and I know HTML very well but I don’t know how to put it in. You said “the default Ebook compile format has a matching style for [that],” but I see only the usual set of styles. Same for Markdown, which I could learn if necessary.

    Also, if I put in raw HTML, won’t that mess up when I compile to PDF?

    I’m on my fifth computer book, so I use Code Span and Code Block a lot. I’ll try putting those few things in my monospace font (I use Menlo) and see if that works. (But I’d still like to know how to make a raw HTML style).

    Thanks,
    Dave Matuszek

    P.S. I love Scrivener.

    1 Like

    By that I mean the “Ebook” compile Format itself, rather than the project. You would need to create a style by that name in your project, and so long as you use the built-in “Ebook” compile format, it should work. It should have lots of styles that aren’t in the project in fact, since a lot of them are used internally by the format.

    To make sure we’re on the same page, go into compile, and double-click on “Ebook” in the left sidebar to edit it. The Styles pane in there is what I’m referring to.

    Also, if I put in raw HTML, won’t that mess up when I compile to PDF?

    Okay, if you need multiple outputs then raw HTML can get in the way, yes. There are ways around that, such as making it so the Format you use to compile to PDF looks for that “Raw HTML” style and deletes the text of it. Then you’d have to supply two different strings, one formatted for rich text and the other for HTML/ePub. For this particular task it might be overkill, but that’s a useful trick to know of for more complex things.

    So all around it may be easiest and most straight-forward to take my other suggestion of using a different style entirely for these equations, rather than code span or raw html. That should work in both outputs without any further customisation.