0

For years I've been using HTML to produce web pages with text flowing nicely around images. Here's an example of the sort of thing:

enter image description here

As you can see, the images are floated left and right, and may overlap in vertical extent. There are also two images side-by-side with no text vertically overlapping.

Using HTML this is trivial, I'm using really old, outdated HTML with tables that are aligned left and right as appropriate, and the text simply flows around it.

The attempts I've made with LaTeX appear to be limited, not allowing images to overlap vertically, and insisting that any paragraph can only overlap with at most one image.

I feel like I must be missing something. I know LaTeX and Tex are page formatting systems - I used TeX for my PhD some decades ago - but extensive searching and several weeks of on-and-off hacking about have failed to produce anything cleaner than using \parshape and doing it all "by hand."

All assistance welcome. I'm using vanilla Ubuntu 14.04 (soon to be 18.04) so can use any commands available on that platform, including pdftex and pdflatex, to name just two.

Thanks in advance.

  • 1
    See what can be done with the plain TeX macro package insbox: it defines the \InsertBoxL and InsertBoxR commands. – Bernard Feb 06 '20 at 18:15
  • It's been decades since I've done anything in TeX "properly", can you provide a minimal example? Meanwhile I'll go and do some reading ... – RiderOfGiraffes Feb 06 '20 at 18:41
  • @Bernard insbox can't vertically overlap the insertions. – Skillmon Feb 06 '20 at 18:58
  • 1
    as written this is an exact duplicate of your last question https://tex.stackexchange.com/questions/527282/getting-text-to-flow-around-images-in-either-tex-or-latex you didn't fill out any of the details I suggested in comments there as to how you want to specify this – David Carlisle Feb 06 '20 at 19:34
  • If you are specifying the positions of the images first and then pouring the text into the non rectangular galley that is essentially easy and done as in my answer before, with some syntax improvements where the size of each cutout is measured from the image rather than specified separately. If you want it to work like a css float right/float left note that that is conceptually much harder in tex than in html as tex is doing a least cost analysis of the whole paragraph for line breaking, so adding a word at the end can change all the linebreaking and so the relative position of the images. – David Carlisle Feb 06 '20 at 19:38
  • It's not a duplicate, as I am no longer asking for plain-TeX. Are you asking what I mean by "float"? I thought that was a standard term. I don't know what you think is missing from my question ... you know a lot more about this than I do, but I don't know what more you think needs to be said. I want to have a page with text. I want some "magic" that specifies "an image goes about here, on the left, taking about 30% width". Then a little later some "magic" that says "now I want an image, about 30% wide, aligned on the right." Then it produces something like the page layout above. – RiderOfGiraffes Feb 06 '20 at 19:39
  • So are you saying that this needs to be done effectively "by hand" using \parshape? All the things I've seen such as wrapfigure and insbox appear not to handle vertical overlaps of image positions ... is that effectively impossible with existing libraries/macros? If so, fair enough, I just thought it would be a common enough requirement that someone would have done it. – RiderOfGiraffes Feb 06 '20 at 19:42
  • 2
    float is a standard term in latex and a standard term in css, but has completely different meanings in the two systems. But basically the main question is do you want to say the image is 5cm down the page, on the right hand side, or do you want to say the image is on the right in the line with the word foobar. My previous answer shows how to do the first (at the tex primitive level) doing the second is a lot harder. – David Carlisle Feb 06 '20 at 19:52
  • I feel like I've answered your questions already. I want to have a bunch of text. In that text I want names of images, and an indication of which side they should go. I want the system to put the images in the document, roughly at the same location in the text as in the input. I don't really know how I can say that more clearly. It seems the problem in communicating what I want is that you know what (La)TeX can do & I don't, & you're trying to interpret what I say in the context of (La)TeX, & it doesn't make sense. How do you want me to proceed, given that I think I've answered your question? – RiderOfGiraffes Feb 06 '20 at 20:06
  • By the way, I really appreciate you taking the time over this, and my frustration is not at you, but at the difficulty of trying to be precise in someone else's domain. Should I go back and completely re-write the question? – RiderOfGiraffes Feb 06 '20 at 20:07
  • OK so you want the images tied to the text rather than page location, that's actually quite hard but I may sketch something out later (but may not:-) – David Carlisle Feb 06 '20 at 20:34
  • Ideally, yes. And thank you for this ... it does, honestly, surprise me that no one has done this before. – RiderOfGiraffes Feb 06 '20 at 20:36
  • traditionally tex is used for "journal" rather than "magazine" layouts and wrapping text around images at all is somewhat rare, or the simpler cases handled by wrapfig are more than enough. You can get tex to do this but it's pushing the boundaries... – David Carlisle Feb 06 '20 at 20:38
  • \parshape is the tex primitive, insbox, wrapfig etc are layered over that to calculate the required shape, my answer to your last question is the same but withoyt any attempt to hide the actual primitive syntax so it contains a literal sequence of dozens of lengths specifying the shape. insbox wrapfig etc are esssentially just measuring the box then having some loops to calculate that list. Obviously the calculations are easier if there is only one cutout or if they don't overlap but having multiple isn't conceptually harder. ... – David Carlisle Feb 06 '20 at 21:12
  • .... But \parshape has to be specified before the paragraph, so css style floats where you position images that you encounter mid-paragraph, based on the existing linebreaking are challenging. – David Carlisle Feb 06 '20 at 21:13
  • I can appreciate that. Again, if I knew more about what TeX is doing, and if I knew the TeX macro languages, I'd have a go at doing it ... I do have some experience in programming. But there's too much to learn, I don't really want to become an expert, and it would be a distraction from actually accomplishing things. I very much appreciate your assistance in this. Now knowing that, in essence, it's not currently possible makes me slightly relieved that I haven't missed something obvious. – RiderOfGiraffes Feb 06 '20 at 21:31
  • If you wanted to try this you would probably be best to try it in luatex as you could program it in Lua rather than Tex (I was wondering about trying that myself, but wont be until the weekend at earliest, and I may not have time at all, which is why I'm dropping more comments than usual here, give some hints) I – David Carlisle Feb 06 '20 at 21:34
  • I've been hunting, and it's not at all clear where to start, or how to do anything. The tutorials do trivial things that are obvious, and the documentation doesn't see to bear any relationship with anything I know. I have no idea where to start. This isn't the forum ... if we were connecting somewhere suitable I could ask more pointed questions that would be trivial for you to answer and actually help me make progress. Alas, this is not that medium. I'll continue to hunt, and look forward to anything you can do for me. Thanks again. – RiderOfGiraffes Feb 06 '20 at 21:55
  • Are you sure you have thought clearly about what you want? In a HTML document for typical rendering on a screen, there is no notion of a "page", and moreover line-breaking for paragraphs of text is done in a naive way. TeX is oriented to a physical page, and things are different. What if you have a word that would otherwise occur on the last line or two of the page, and you ask for a tall image to be placed to its right? What should happen: should the image move to the next page (as it won't fit here), should earlier paragraphs be moved about? What if consecutive words each specify an image? – ShreevatsaR Feb 07 '20 at 00:37
  • 1
    Of course ConTeXt can do this. So can DocScape/Speedata Publisher. – Martin Schröder Feb 07 '20 at 11:59
  • @ShreevatsaR - Yes, I have thought about this. I know the difference between HTML and (La)TeX, I know that they have different audiences. So do I. Some of my readers will read the HTML, others will read the document. I'd like to be able to convert the HTML to (La)TeX ... I do know what I'm asking. If an image would occur close to the page end, I'd move it. – RiderOfGiraffes Feb 07 '20 at 12:42
  • @ReinstateMonica-M.Schröder Great ... can you provide a specific example of how to do this? My reading about it is inconclusive to say the least, and a single, well-chosen example will probably solve my problem. Thanks. – RiderOfGiraffes Feb 07 '20 at 12:42
  • For ConText's \placefigure command, wiki https://wiki.contextgarden.net/Floating_Objects has some full example code. – Cicada Mar 02 '20 at 10:40
  • The floatflt package (from 1998) does right and left floats within a paragraph. If the images are small and ornamental, as drop-caps, lettrine package may be a design choice; if the images are instructional, marginpars could work, or even better, the wide-margined tufte-book class. Unrelated: The two design choices, windowed-material and typeset-material, allow bi-directional questions: How can I get my PDF to flow like html/css/js? versus How can I get my html/css/js to look like it has been typeset? Would a reader necessarily map one to the other, stylistically? Or look for craft? – Cicada Mar 03 '20 at 11:02
  • Pandoc looks interesting (https://pandoc.org/demos.html); there are many conversion questions (e.g., https://tex.stackexchange.com/questions/1507/how-to-create-pdf-and-html-output-from-the-same-source ). Scanning through those, robust solutions seem to be clustering around the method of a master (I would expect XML) which then 'forks' into Latex->PDF and into (X)HTML/CSS/js – Cicada Mar 03 '20 at 11:33
  • -> @Cicada : Thanks for the suggestions. I'll go have a look at floatflt to see if I can make that work. I've tried pandoc several times and never managed to get it to work on my platform. The error messages are opaque, and searching has never produced an answer. I'll give it another go when I get the chance. Thanks. – RiderOfGiraffes Mar 07 '20 at 16:56

0 Answers0