Suppose I have text like this in a label
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam
et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
takimata sanctus est Lorem ipsum dolor sit amet.
How do I change the colour of the the sentence "At vero eos et..." starting in the second line?
I don't believe this is possible with the UILabel class. However, it wouldn't be too hard to do this with some simple HTML in a UIWebView.
[myWebView loadHTMLString:#"Some normal text. <font color=\"red\">Some red text.</font>" baseURL:nil]
Let me know if this works well for you.
You can't do that with a standard UILabel. You'd either have to use multiple UILabels or take a look at CoreText which would also do what you want - http://developer.apple.com/library/mac/#documentation/StringsTextFonts/Conceptual/CoreText_Programming/Introduction/Introduction.html.
Related
I am using kramdown in jekyll. If I need to define inline math expression I have to use double dollar notation inside paragraph like this:
Lorem ipsum dolor sit amet, consectetur $$e^{i\theta}=\cos(\theta)+i\sin(\theta)$$
adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
and when I want to use display mode I have to use double dollar notation outsite of paragraph like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
$$ \left[ \frac{-\hbar^2}{2\mu}\nabla^2 + V(\mathbf{r},t)\right] \Psi(\mathbf{r},t) $$
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
ea commodo consequat.
But this is ugly and it breaks LaTeX convention of single dollar for inline and double for display.
How can I force this conventional latex notation in kramdown ?
Thank you for help
I'm using bookdown to prepare some documents.
For some reasons I need to have bigger font size for headings and main text and smaller font-size for tables.
The simple minimal reproducible example is below:
---
papersize: a6
geometry: 'landscape'
site: bookdown::bookdown_site
output:
bookdown::pdf_document2:
latex_engine: xelatex
header-includes:
- \usepackage[fontsize=15pt]{scrextend}
---
Below is a table with narrow first column and wide second column:
| **Seq** | **Description** |
|:---:|-------------|
| `1` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
| `2` | Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. |
Link to intermediate LaTeX file.
Is it possible to decrease font size for tables to make it smaller than now?
You can force a smaller font size for longtable by adding
\AtBeginEnvironment{longtable}{\tiny}
to your header-includes
So, I am serialising an object in Ruby on Rails into JSON format, using to_json. The output produced is:
'{"description":"---\n- Nulla adipisci quia consequuntur nam ab et. Eius enim ad aut. Asperiores recusandae\n labore exercitationem.\n quos provident.\n","id":295,"name":"Animi enim dolorem soluta eligendi inventore quia distinctio magni.","privacy":0,"updated_at":"2012-11-18T22:24:17Z","user_id":1}'
This needs to be parsed by JSON.parse to deserialise the object in client-side javascript. At the moment, this is failing because of the newline characters \n in the "description" value. I've tried to encode the characters appropriately using gsub("\n","\\n") and other permutations, but I can't seem to find a string or regular expression that will correctly match the newlines (and only the newlines). I have tried /\n/, '\n', "\n", "\\n" (this matches everywhere on the string, for some reason), /\\n/ and so on, but haven't been able to find anything. Any ideas what I am missing?
Update: here's the code (javascript, but with embedded ruby) I'm trying to use to populate the javascript object (it's in an ERB view, hence the angle brackets):
var object = JSON.parse('<%= raw #object.to_json %>');
to_json is not overridden in my object code, just the standard rails method.
j = %Q!{"description":"---\n- Nulla adipisci quia consequuntur nam ab et. Eius enim ad aut. Asperiores recusandae\n labore exercitationem.\n quos provident.\n","id":295,"name":"Animi enim dolorem soluta eligendi inventore quia distinctio magni.","privacy":0,"updated_at":"2012-11-18T22:24:17Z","user_id":1}!
j.gsub! /\n/, '\\n'
JSON.parse j
# => {"description"=>"---\n- Nulla adipisci quia consequuntur nam ab et. Eius enim ad aut. Asperiores recusandae\n labore exercitationem.\n quos provident.\n", "id"=>295, "name"=>"Animi enim dolorem soluta eligendi inventore quia distinctio magni.", "privacy"=>0, "updated_at"=>"2012-11-18T22:24:17Z", "user_id"=>1}
Make your life easy, use single quotes around escaped characters when you need to manipulate them.
After the update…
var object = JSON.parse('<%= raw #object.to_json.gsub(/\n/, %q!\\n!) %>');
Your JSON includes a YAML string, so don't waste time trying to remove the line feeds, or you'll make things worse, or at least cause yourself to do too much work.
require 'json'
require 'yaml'
json = '{"description":"---\n- Nulla adipisci quia consequuntur nam ab et. Eius enim ad aut. Asperiores recusandae\n labore exercitationem.\n quos provident.\n","id":295,"name":"Animi enim dolorem soluta eligendi inventore quia distinctio magni.","privacy":0,"updated_at":"2012-11-18T22:24:17Z","user_id":1}'
hash = JSON[json]
puts YAML.load(hash['description'])
Outputs:
Nulla adipisci quia consequuntur nam ab et. Eius enim ad aut. Asperiores recusandae labore exercitationem. quos provident.
The JSON, after decoding back into a Ruby hash, looks like:
{"description"=>
"---\n- Nulla adipisci quia consequuntur nam ab et. Eius enim ad aut. Asperiores recusandae\n labore exercitationem.\n quos provident.\n",
"id"=>295,
"name"=>"Animi enim dolorem soluta eligendi inventore quia distinctio magni.",
"privacy"=>0,
"updated_at"=>"2012-11-18T22:24:17Z",
"user_id"=>1}
To turn it back into a true JSON string, with description not encoded as YAML, use:
hash['description'] = YAML.load(hash['description']).shift
puts hash.to_json
Which now looks like:
{"description":"Nulla adipisci quia consequuntur nam ab et. Eius enim ad aut. Asperiores recusandae labore exercitationem. quos provident.","id":295,"name":"Animi enim dolorem soluta eligendi inventore quia distinctio magni.","privacy":0,"updated_at":"2012-11-18T22:24:17Z","user_id":1}
in my application I have a UILabel with a lot of text inside. When the user performs a research I want to highlight the background under the text searched by the user.
Here an example from "Preview" in MacOSX.
The user searches silence and this word is highlighted in the text.
Any ideas ?
Thanks.
You'll need to enable the 'attributed' text of the UILabel (or UITextView/custom view). Then you'll need to find/make a nice/fast algorithm to change the color (bg/text) color of some parts of the text. You should be able to find quite a lot on 'attributed string' algorithms to mark some words/matches.
Please check also http://iphonedevelopment.blogspot.be/2011/03/attributed-strings-in-ios.html
In case of, it can maybe be easier/quicker to use a webview by making a custom HTML with the matched-words in another color/bg-color. A webview can almost look like a normal label, and offers even the option to use links/images/..., which can improve the user-experiences in some cases
Maybe this is an old question. But I think this will help to someone.
To highlight a part of text in UILabel, I have written an open source named HighlightLabel.
You can simply specify the hightlightText and highlightColor to highlight it.
_highlightLabel.text = #"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.";
_highlightLabel.highlightText = #"Lorem ipsum dolor sit er elit lamet";
_highlightLabel.highlightColor = [UIColor yellowColor];
You'll have to use NSAttributedString for this.
This might also help. It is a subclass of UILabel that draws an NSAttributedString and also provides convenience methods for setting the attributes of an NSAttributedString from UIKit classes.
Once desired letters/Characters are found, highlight that part of UIView or anything you are using there.
Hi I am using RedCloth, Rails 3.
Currently I splitling a long text based based on string "-BREAK-".
How do I split text based on character length without splitting in the middle of a sentence.
E.g.,
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas at purus eu nisl consequat mattis. Morbi pretium eros eget erat ornare elementum.
Vivamus in dui sit amet tellus bibendum volutpat. Sed lorem sem, porttitor at mattis quis, volutpat sed quam. Vestibulum eu justo nec dui ullamcorper molestie. Sed eleifend malesuada mattis. Curabitur eleifend elit vitae justo feugiat iaculis. Etiam sed lectus eu quam suscipit fermentum id a sem.
Phasellus sed odio eu urna gravida venenatis venenatis non justo. Praesent tincidunt velit adipiscing ligula pretium commodo. Cras blandit, nibh ac sagittis egestas, enim odio rutrum metus, vel hendrerit felis urna cursus odio. Maecenas elementum erat et arcu vulputate eu fermentum orci semper. Proin luctus purus sit amet nibh blandit cursus.
That will be comprise one page. It's about 794 characters.
First you should split your text to single sentences.
Here's a simple, far-from-perfect way for doing this (I'm sure you could find plenty of more complete patterns elsewhere):
'Gsda asd. Gasd sasd. Tfed fdd.'.scan(/(.+?\.) ?/).map(&:first)
#=> ["Gsda asd.", "Gasd sasd.", "Tfed fdd."]
Then, you should join these sentences, keeping an eye of the paragraph length. You can use something like this:
# using words as units, but sentences are just the same:
s = ['foo', 'bar', 'beef', 'baz', 'hello', 'chunky', 'bacon']
LEN = 7 # minimum length of a paragraph
s.inject([]){|a,i|
if !a.last || a.last.length > LEN
a << i
else
a.last << " #{i}"
end
a
}
#=> ["foo bar beef", "baz hello", "chunky bacon"]
I don't think there's any built in logic for this, so you should just look for "." with a nice regex also specifying that it has to be straight after a word (not whitespace), followed by a space and a capital letter.
Edit: that should give you an array of occurrences from which you can pick the one closest to the character limit.