How can I make a print output (but not other outputs like plots etc.) centered? For example this code:
print("I want this text centered")
If you don't mind using HTML, then you can center text as follows:
from IPython.core.display import display, HTML
content = "Hello World"
display(HTML(f"<div style='text-align:center'>{content}</div>"))
Which will produce the following:
You can also create a re-useable function that can be used instead of print:
def centered(content):
display(HTML(f"<div style='text-align:center'>{content}</div>"))
Which would be used as follows:
centered("My centered text.")
And produces:
<h1><center>Centered text!</center></h1>
Related
I am trying to get text value in TMPro Text component without markup tags but haven't found any solutions.
Say, <b><color=red>Hello </color><b> world is the value in TMPro Text, and I just want Hello world in c# script.
Bear in mind that tag <b> and color will change, so I would love to remove tags dynamically, meaning I would like not to replacing each tag by text.replace("<b>", "") kind of things.
Does anyone know how to do it?
I dont know about the option of using HTML on tmp but you can attach the text to your script by create a new variable like that:
[SerializeField] TMP_Text textVar;
then you can drag you tmp game object to the component that include this script
and the you can change the text like that:
textVar.text = "what ever";
or get text like that:
string textString = textVar.text;
for the color you can use
Color color = textVar.color;
You can use TMP_Text.GetParsedText () to get the text after it has been parsed and rich text tags removed.
Alternatively you can also use regular expressions to search a string for rich text tags, and remove them while preserving the rest of the string.
using System.Text.RegularExpressions;
public static string GetString (string str)
{
Regex rich = new Regex (#"<[^>]*>");
if (rich.IsMatch (str))
{
str = rich.Replace (str, string.Empty);
}
return str;
}
There are some markers in my template. Sometimes markers can be empty, can I catch this situation? Something like:
if !###NEWS_IMAGE###
Markers or Subparts have no logic in the template.
All logic has to be done while generating the replacement text.
IN PHP you can use the usual PHP control structures.
if you fill the markers with Typoscript you can use the options of stdWrap.if to fill in any replacement string, even an empty string.
in this way you can condition label to show only if the value is set:
marks {
something = TEXT
something.field = title
something.wrap = the title is |
something.wrap.if.isTrue.field = title
something.ifEmpty = no title given
}
I have a website structure where I use functions to maximize code reuse. Sometimes I need a certain page to add more scripts or stylesheets to the head of the html page. The code below does what I want, except I'm forced to use a div or some other tag to contain the rest of the scalatags. I don't really want a random div tag in my document's head part. Is there some generic/empty tag I could use for this purpose? (tag("") makes a compilation error btw.)
import scalatags.Text.all._
class Temp {
def document = html(
head(
script("some javascript"),
extraScripts
),
body(
h1("A website")
)
)
def extraScripts = div( // <-- This div is the part I want to change
script("More scripts"),
script("and what not")
)
}
I have the following code in my python script. How do I change the image of my button instead of the default ugly looking button?
import web
from web import form
render = web.template.render('templates/')
urls = ('/','index')
register_form = form.Form(
form.Textbox("name",size=40, description="Please enter name: "),
form.Button("Query", type="submit", description="Query")
)
I was hoping to have an effect similar to this:
< button>< img src="index.png">< /img>< /button>
The html option allows you to enter any html tags. :)
form.Button("Query", type="submit", description="Query" html="<img src="hello.png"/)
Using iTextSharp i'm trying to align an image so that it gets embedded in a paragraph. I can do it like this:
iTextSharp.text.Image image;
image.Alignment = Image.ALIGN_RIGHT | Image.TEXTWRAP;
document.Add(image);
document.Add(new Paragraph("Large string of text goes here"));
But the image comes out on the top right with the text surrounding it (kind of like an L)
What I want is the text to be a few paragraphs then the image with text below it (kind of like a C). Does anyone know how I would do this VIA iTextSharp?
Edit:
I also tried
iTextSharp.text.Image image;
image.Alignment = Image.ALIGN_RIGHT | Image.TEXTWRAP | Image.ALIGN_MIDDLE;
document.Add(image);
document.Add(new Paragraph("Large string of text goes here"));
But it was displayed with the image at the top and the text below it. There was no textwrap in effect.
The Phrase and the Paragraph objects do behave differently. Try changing to:
image.Alignment = 6;
document.Add(image);
document.Add(new Phrase("Large string of text goes here"));
This worked for me in VB. ( I had to change the image alignment to the sum of the integer values for ALIGN_RIGHT and TEXTWRAP to get this to work properly).
ALIGN_RIGHT = 2
TEXTWRAP = 4
Your image was displayed at the top of the page because it was the first thing added to the document, and the text was added after it.
You can move the image down by either setting its absolute position, or by adding some of your text to the document, then adding the image, then adding the rest of your text.
The easiest way to embed image into paragraph is to use InlineImage from PDFFlow library.
InlineImage was created exactly for this purpose.
Example of adding an inline image with margins:
var imagePath = "imageFile.png";
DocumentBuilder.New()
.AddSection()
.AddParagraph()
.AddTextToParagraph("Inline image")
.AddInlineImage(imagePath, new XSize(16, 16), ScalingMode.UserDefined)
.SetMarginLeft(8)
.SetMarginRight(8)
.ToParagraph()
.AddText("in paragraph.")
.ToDocument()
.Build("Result.pdf");
The above code will generate the following:
Here are business documents examples with source code: Examples.
Hope, this will help.