in slim how can i place in image between 2 lines of text? - slim-lang

I wand to display logo image wrapped between h1 style lines of text. I am using slim. How can I rewrite this code that it shows all in one line?
h1 text1
=image_tag 'image'
h1 text 2
or
h1 text1 =image_tag 'image' rest of text1
is that possible?

figured this out:
h1
|text1
=image_tag "image"
|text2
the solution was inspired by this question which has a great example of using Slim:
rails slim indent syntax error

Related

How to align text in restructured text so that will be aligned in latexpdf?

I've tried to write own rst-classes and apply it to H1, H2 (headers like ====== or ~~~~~~~) and it works good when I make html. But in PDF it looks like headers, it is unexpected.
Please help me to solve this problem. I need to provide my report with good title page for my university but I don't know how to do it in ReST.
P.s. Sorry for my english, I'm russian =)
In the PDF here https://docdro.id/NRaWdDf each part is on its own page, like this
and the Contents.rst is at https://github.com/greenstm137/RWOfStudents/blob/4c8153969ed4d7e8de937d0ae33ccbaa7af03cdd/source/contents.rst
You might want to add raw latex code to center it. Try this:
|lstartcenter| My Text is Centered! Cool! |lendcenter|
.. |lstartcenter| raw:: latex
\begin{center}
.. |lendcenter| raw:: latex
\end{center}
This code sets a start and an end tag with "raw:: latex" which inserts raw latex code if you compile it to latex.
"|lstartcenter|" starts making it centered, while "|lendcenter|" ends centering it.

hexapdf gem make text ordered list rails

i want to generate pdf with hexapdf gem
I want to have nice inline ordered list.
This is what i do
note = "1. Sub text 1: \n \tsub text 2"
note_text = HexaPDF::Layout::TextFragment.create(
note,
font: pdf.document.fonts.add("Helvetica", variant: :bold),
font_size: 9
)
tl.fit([note_text], 470, 100).draw(canvas, 0, y - 1)
it generate text like this below
the problem is text 'sub text 2' is not inline with text 'sub text 1'.
I want have text 'sub text 2' start inline with the start of text 'Sub text 1' (after '1. ')
how to do it?
Thanks
It seems it does not print the tabulation correctly, but anyway, it's not going to produce a 100% correct result.
To correctly align "Sub text 1" with "sub text 2", you have to create another text fragment, which you place next to a text fragment with your "1."
In other word: you create a text fragment for your paragraph, and naturally, lines will all start at the beginning.
Looks like the \t doesn't work. This is a quick hack - how about adding 3-4 spaces before sub text 2?
I tried it in IRB and it works as follows:
irb(main):003:0> puts "1. Sub text 1: \n sub text 2"
1. Sub text 1:
sub text 2
However, since Helvetica isn't a mono font, you'd need to play around with how many spaces would "fake" the appearance of the document being formatted.
Otherwise there might be a gem that handles more advanced text/document formatting.

show highcharts node text on top if the text is to long

According to this question
show highcharts node text from beginning if the text is to long
it is possible to use dataLabels.nodeFormat to display only the name which is correct. But the text stands all in one line, and you cant read the whole text "Merkmale | Makro zur Prüfung" because it gets cut off in the end. If you don't use datalabels.nodeFormat the text will be wrapped inside the label automatically. Is there any solution for this?
I think that using this CSS config is a solution to your issue:
.highcharts-data-labels span {
word-break: break-word !important;
white-space: normal !important;
}
Demo: https://jsfiddle.net/BlackLabel/36y52qcf/

figure caption centering in nbconvert?

I have cells underneath figures in an ipython notebook that contain figure caption text. I would like them to be centre('center')-aligned. I use "< center >" in the markdown, which gives exactly the appearance I'm after in the notebook. But when nb-converting to latex, the text gets shunted over to the left.
So is there a way to get nbconvert to recognize text alignment in markdown cells when converting to latex?
Thanks.
You have actually asked two different questions:
is there a way to get nbconvert to recognize text alignment in markdown cells
figure caption (centering) in nbconvert
ad 1)
To convert the markdown to latex pandoc is used. Unfortunately, pandoc removes raw html from markdown if converted to latex (if also removes raw latex when converting markdown to html).
So it is not that straight forward to use html tags to format the output in both html and latex. This formatting may be achieved based cell metadata but that is not that trivial currently.
ad 2)
Nevertheless it is possible to create caption like text to work with html and latex.
Here we have to distinguish between caption for pyout or stream data (e.g. Ipython.display.Image) and markdown images.
pyout and stream
A possible approach is to create a Caption class like
class Caption():
def __init__(self,s):
self.s = s
def _repr_html_(self):
return '<center>{0}</center>'.format(self.s)
def _repr_latex_(self):
return '\\begin{center}\n'+self.s+'\n\\end{center}'
which is called after the image. Note that both should be called with the IPython.display.display method, e.g as oneliner
display(Image('image.jpg'),Caption('Figure Caption'))
This approach allows process the captiontext with python, e.g. to add figure numbers.
If you want to add such a caption to a matplotlib plot, it is a bit more tricky as the wrong ordering has to be overcome. A possible approach is to plot using this snippet
%matplotlib inline
plt.plot([1,2])
f=plt.gcf()
plt.close()
display(f,Caption('Plot'))
It may be noted the the default latex template of IPython 1.x doesn't play well with this approach, as here, image and caption are only loosely coupled and thus, vertical space might be included during latex compiling. The latex_basic template works much better. In IPython master the default templates are working fine.
markdown images
Markdown allows to use images like
![Caption](/files/image)
When converting to latex pandoc can take the Caption part and create a real latex caption.
Similar, when converting to html the caption gets embedded in a caption class to be easily styleable using css.
However, currently IPython requires a "/files/" prefix which is currently not removed, thus the image file won't be found by latex. (Fixed by now)
Be aware that these markdown image calls do not embed but only link the image into the ipynb file, therefore, the image has to remain available.

rails gem prawn, image and anchor

Can you tell me how to insert image which will be a link to for example page 20? I know how to make with normal text:
text "<link anchor='page20'>Go to page 20</link>", :inline_format=>true
and then on page 20 I have
add_dest('page20', dest_fit(page.dictionary))
but how to do this with image ?
Partly thanks to lightswitch05 for some prodding in the right direction, I've found a way to get the effect I want through this inelegant way:
Insert an image in a bounding_box (the page cursor is at this point at the bottom of the image)
Move the cursor back up to the top of the image
Insert a text link over the image (in my case I just used however many vertical bars '|' were needed to cover the image)
Confirm visually that the clickable link area is about the same as the boundaries of the image
Make the text link transparent, and voilà, it looks like you're clicking the image.
Here's some example code (measurements not exact; there was a lot of tweaking involved):
bounding_box([0, cursor], width: 35) do
image open("http://mysite.com/remote_image.jpg"),
fit: [35, 35],
align: :center
move_up 35
transparent(0) do
formatted_text([{
text: "|||", # placeholder
size: 40,
link: "http://example.com/"
}], align: :center)
end
# stroke_bounds
end
Needless to say, this experience has got me looking a bit more at Wicked PDF in order to do what I think I want to do with PDFs.
I'm sure a better/more elegant solution exists, so I'm not planning on considering this my final answer.
Prawn does not support this functionality. In fact, even if you placed a formatted_text_box over an image and fill it with white space, it still will not work. An anchor has to include text to work. If you don't mind having text over your image, then that might be a solution.
Prawn's own readme states:
One thing Prawn is not, and will never be, is an HTML to PDF generator.
After dealing with many of Prawn's shortcomings, I've switched to using wicked_pdf for my Ruby on Rails PDF generation and have been very happy with it. If you can do it in html & css, it can be done with wicked_pdf.

Resources