Non-breaking space between lines - ruby-on-rails

How could I join two HAML lines with a non-breaking space (& nbsp;) and no actual space, e.g.:
= 'foo'
%a(href='http://example.com') bar
I tried using the succeed helper, but a space is still generated between them. I want to remove the space.

How did you use succeed? Where did the space end up?
Did you combine it with the whitespace removal chars ("<" and ">") or try them on their own?
= succeed ' '.html_safe do
= 'foo'
%a(href='http://example.com')> bar
This produces:
foo <a href='http://example.com'>bar</a>
Is that literally what you want? It is "two lines joined by a non-breaking space with no actual space."
(IMO, HAML is meh for inline content, and just no fun. Nice for layout.)

Related

Alignment in flextable correct in Rstudio viewer, incorrect in Word

I am trying to left align some columns in a few of my tables. Most of the time this works no problem, but other times, the columns selected with:
ft <-align(ft, j=1:2, align = "left", part = "body")
ft <-align(ft, j=4:6, align = "left", part = "body")
look correct in the Rstudio viewer. I used a loop to make 39 tables and want to add them to a word document using officer
However, when printed to a word doc using:
doc <- read_docx() %>%
body_add_flextable(tab0)
body_add_break(doc, pos="after")
for (i in 1:38) {
body_add_flextable(doc,get(paste0("tab", i)), align = "left")
body_add_break(doc, pos="after")
}
print(doc,target=documentname)
it center aligns the columns (only changes those that were left aligned). When I click on the text, it says that they are left aligned, but then I center and re-left align and that fixes the issue. I have only noticed the issue which character variables
I tried triming whitespace with
trimws() before I make the flextable with no luck.
I tried other alignments and the issue only seems to occur with left alignment.
I don't believe my code to be wrong, since it works for my other tables. Therefore, I think trying to make reproducible code would be a waste of time.
Therefore, I'm assuming the text itself is causing the issue? Does anyone know what could be wrong with the character variables themselves? Or any other ideas?
Fixed it...
Somewhere within my flextable manipulation this leading white space was added.
So trimming white space before didn't do anything. Had to trim right before naming my table (within a loop). Here is the loop I used to correct it.
for (j in 1: length(ft[["body"]][["content"]][["content"]][["data"]])){
ft[["body"]][["content"]][["content"]][["data"]][[j]][["txt"]] <- trimws(ft[["body"]][["content"]][["content"]][["data"]][[j]][["txt"]])
}

Fragile Space – opposite of non-breaking space

Under iOS I'm wondering if there is a kind of "extra fragile" space that I could put in to a string.
If I display it in a UILabel (or other control), and the text needs to be split over >1 line, then the layout would try to split on a a fragile space if it possibly can.
Eg, if <> is a fragile space symbol, then the string "All on one line if possible<>but this on another line if needed." would display as:
All on one line if possible
but this on another line if needed.
… assuming that there wasn't room for the whole string on one line.
Or perhaps the concept is more a "Newline here if you need to".
Maybe something with ranges in NSAttributedString that can describe where breaking should be preferred? Or some other way to specify this to a label?

In a UILabel, is it possible to force a line NOT to break in a certain place

I have a UILabel that is supposed to be two lines long. The text is localized into French and English.
I'm setting the attributedText property of the label. The text is constructed from three appended strings, say textFragment1, textFragment2 and textFragment3. The middle string is actually an image created with an NSTextAttachment.
I want to make sure that textFragment2 and textFragment3 are on the same line. The first string may or may not wrap depending on how long it is. The problem is that my French text is currently fairly short, so the line is wrapping after textFragment2.
I have fixed this temporarily by adding a line break symbol in the localized French text for textFragment1. I don't really love this solution though. I was wondering if there is a way to treat textFragment2 and textFragment3 so that they will always be together on the same line.
You could use a non-breaking space (\u00a0) to join textFragment2 and textFragment3. This character looks just like a normal space—i.e. it results in the same amount of whitespace—but line breaking will not take place on either side of it.
You could also use a zero-width space (\u2060). Using this character will not result in any whitespace, but it will still prevent line breaking on either side. This is what you want if you don’t want any space between textFragment2 and textFragment3 but you still want to prevent line breaking there. (It’s also useful if you have a word with a hyphen in the middle of it but you want to prevent the line from being broken after the hyphen.)
You can read more about these kinds of characters on Wikipedia.

Align UITextView Right and Left.

I have UITextView, which is left aligned.
When last word does not fit on current line it goes to next line leaving spaces on end of line.
which does not give good look and feel.
So, what I want that if words of particular line feels the spaces left at end.
i.e. Spaces between two words can dynamically varies.
Here I am giving example of Scenario:
The width of text view,never put off until (here tomorrow does not fit,so it goes to next line leaving spaces).
Tomorrow what you can avoid all together.
So, problem is it does look good.
What I want is:
The width of text view never put off, until (varying spaces shown by)
tomorrow -what -you -can
avoid --all -- together.
Thanks in Advance.
There is no setting for justified aligment for text you only have center, left and right. If you want justified aligment where every line has the same amount of characters or something like that you can format the text entered to have carriage returns after x amount of characters or words, or something like that.

How to set tab stops after whitespaces in LaTeX?

I'm trying to set tab stops in LaTeX in the tabbing environment. My problem is that I want to set a tab stop after a number of whitespaces. The problem is that LaTeX of course ignores multiple whitespaces, and it seems to only support setting tab stops after actual text.
What I would like to be able to do is format the arrows below so that they line up together.
A -> B
CD -> A
BDD -> F
The problem is that the extra spaces after the characters on the left of the arrows are ignored for the purposes of setting the tab stop. What is the solution?
The tabbing environment allows to set tab stops and position text accordingly; it may be used to simulate simple tables.
\= in the first line sets a tab stop, \> advances to the next tab stop in the second line and below.
Please note that tabbing does not expand tab stops, so you need to ensure they are placed wide enough from each other. For example, I put some nonbreakable spaces after A in the first line:
\begin{tabbing}
A~~~~ \= $\to$ \= B \\
CD \> $\to$ \> A \\
BDD \> $\to$ \> F \\
\end{tabbing}
The result looks like
Using tables (e.g. tabular) is often easier, but tabbing allows to redefine tab points later, so it may be used to simulate indented text, like source code.
See also: LaTeX: tabbing.
If you want this in math mode, put \usepackage{amsmath} in your preamble, and try
\begin{align*}
A &\to B \\
CD &\to A
\end{align*}
The ampersands are invisible, and are aligned with each other, so the arrows will line up.
This can also be done in text mode as a table (without needing the amsmath package):
\begin{tabular}{r #{$\to$} l}
A & B \\
CD & A
\end{tabular}
With the # expression in the column specification, the columns will be separated by whatever symbol you like -- in this case, the arrow -- thus aligning that symbol between rows.
Use {\hskip 4em} to specify whitespace four font-width spaces wide, or what have you. There are a number of prespecified whitespace characters in Latex, such as \qquad for \hskip2em.
\hskip whitespace specified in this way is inflexible, that is, Tex will not change the amount of whitespace, but you can use something like {\hskip 3em plus 1em minus 1em} for space that tries to be 3ems long, but can stretch or shorten to between 2ems and 4ems.
If you want to use tabbing (instead of e.g. tabular), you can use kill to make a "template" line that sets the stops. See http://latex.computersci.org/Reference/TableEnvironments.

Resources