On Nov 5, 2024, at 1:15 AM, Peter Flynn <
angleb...@gmail.com> wrote:
> I just tried this out so I now see the problem, sorry. I was confused by your use of the word "inline" which doesn't mean what I think you wanted ("inline" means "within the flow of the surrounding text", eg inside a paragraph). Both your examples are block-level; one just happens to be a float and the other one not.
Yeah, sorry. I guess I meant “here."
> I'm not sure that it's a good thing to have floats which don't have a caption or number (or at least some kind of handle or label); otherwise when they do float away from their point of reference, how are you going to point readers at them?
What I gave was a minimum working example — and those things aren’t necessary for one. My real document has those things.
> I'm also not sure that the authors of the listings package envisioned some block-level listings being used as floats and some as non-floats within the same document, so this may be the reason for the extra spacing.
Well, that seems kind of odd — like they’ve never written any documents that explain programming. For actual full listings, I use float. For _very_ small excerpts to explain listings, like 1 or 2 lines, I don’t use float. For example, the following would use float (and a caption):
#include <stdio.h>
int main()
printf( “hello, world!\n” );
}
Listing 1.1: A first program
In subsequent explanatory text when I want to call out a specific line from a listing, I don’t use float:
In the previous program, the line:
#include <stdio.h>
includes the text from the standard library file stdio.h into your program.
For 1-liners like that, it seems both silly and overkill to make them float and give them a listing number. Also for 1-liners, it doesn’t matter if it gets pushed to the top of the next page.
In both the float and non-float cases, I want the space before/after listings (whether full listings or 1-linters) to be the same.
To me, such use seems obvious.
> Your solution seems to be pretty much the best way.
Thanks.
> You might let the authors know the problem and your solution in case they'd like to incorporate it into a future version.
OK.
- Paul