Can I define powerpoints or presentations in raw text? - latex

Hi Guys : I wanted to create a power point presentation using a raw text file, so that i can rapidly edit the file and see the results, gauranteed with uniform formatting. Basically, I'm talking about separating the data content from the presentation.
How can I do this ? Im thinking that maybe Latex could be a choice. I've also seen that there are API's for Powerpoint and open office presentations.

Powerpoint exposes it's API via COM - which makes it possible to do (almost) anything that you can do in the GUI in any programming language that supports COM. The difficulty is that the API changes between releases. One way to scope out the API is to use the macro recording facility to manually do one slide, and then translate that to your target language.
I've got some old (not tested recently) python code for Powerpoint 2003 that should give you an idea of what the code might look like depending on your layout needs.
from win32com.client import Dispatch
ppLayoutTitle = 1
ppLayoutText = 2
def writePresentation( fname, data ):
pptApp = Dispatch('Powerpoint.Application')
pres = pptApp.ActivePresentation
aw = pptApp.ActiveWindow
slides = pres.Slides
for item in data:
t1 = item[0]
t2 = item[1]
stype = item[2]
assert(stype in [ppLayoutTitle,ppLayoutText])
s = slides.Add( slides.Count, stype )
aw.View.GotoSlide(s.SlideIndex)
s.Shapes.Item(1).Select()
aw.Selection.ShapeRange.TextFrame.TextRange.Select()
aw.Selection.ShapeRange.TextFrame.TextRange.Characters(Start=1, Length=0).Select
tr = aw.Selection.TextRange
tr.Text = t1
s.Shapes.Item(2).Select()
aw.Selection.ShapeRange.TextFrame.TextRange.Select()
if stype == ppLayoutText:
aw.Selection.ShapeRange.TextFrame.TextRange.ParagraphFormat.Bullet.Visible = 0
aw.Selection.ShapeRange.TextFrame.TextRange.Characters(Start=1, Length=0).Select
tr = aw.Selection.TextRange
tr.Text = t2
slides.Range(slides.Count).Delete()
pres.SaveAs(fname)
Edit:
Openoffice (that can export to powerpoint) also ships with it's scripting API that could be used to solve similar problems.

If all you need is slides with titles and bulleted text, it's quite simple. Create a txt file that looks like this (use the TAB key in place of below):
Slide 1 Title
<tab>Bullet Level One Text
<tab><tab>Bullet Level Two Text
<tab>Back to Bullet Leven One again
Slide 2 Title
Slide 3 Title
<tab>More Bulleted text
<tab><tab>Tufte hates us by now
<tab><tab>But we don't care, do we?
Slide 4 Title
And so on. Save the file, start PowerPoint, choose the file open command, choose Outline or files of all types in the file open dialog box and select your TXT file. Done.

Related

`knitr_out, `file_out` and `vis_drake_graph` usage in R:drake

I'm trying to understand how to use knitr_out, file_out and vis_drake_graph properly in drake.
I have two questions.
Q1: Usage of knitr_out and file_out to create markdown reports
While a code like this works correctly for one of my smaller projects:
make_hyp_data_aggregated_report <- function() {
render(
input = knitr_in("rmd/hyptest-is-data-being-aggregated.Rmd"),
output_file = file_out("~/projectname/reports/01-hyp-test.html"),
quiet = TRUE
)
}
plan <- drake_plan(
...
...
hyp_data_aggregated_report = make_hyp_data_aggregated_report()
...
...
)
Exactly similar code in my large project (with ~10+ reports) doesn't work exactly right. i.e., while the reports get built, the knitr_in objects don't get displayed as the blue squares in the graph using drake::vis_drake_graph() in my large project.
Both projects use the drake::loadd(....) within the markdown to get the objects from cache.
Is there some code in vis_drake_graph that removes these squares once the graph gets busy?
Q2: file_out objects in vis_drake_graph
Is there a way to display the file_out objects themselves as circles/squares in vis_drake_graph?
Q3: packages showing up in vis_drake_graph
Is there a way to avoid vis_drake_graph from printing the packages explicitly? (Basically anything with the ::)
Q1
Every literal file path needs its own knitr_in() or file_out(). If you have one function with one knitr_in(), even if you use the function multiple times, that still only counts as one file path. I recommend writing these keywords at the plan level, e.g.
plan <- drake_plan(
r1 = render(knitr_in("report1.Rmd"), output_file = file_out("report1.html")),
r2 = render(knitr_in("report2.Rmd"), output_file = file_out("report2.html")),
r3 = render(knitr_in("report3.Rmd"), output_file = file_out("report3.html"))
)
Q2
They should appear unless you set show_output_files = FALSE in vis_drake_graph().
Q3
No, but if it's any consolation, I do regret the decision to track namespaced functions and objects at all in drake. drake's approach is fundamentally suboptimal for tracking packages, and I plan to get rid of it if there ever comes time for a round of breaking changes. Otherwise, there is no way to get rid of it except vis_drake_graph(targets_only = TRUE), which also gets rid of all the imports in the graph.

"For all" using Apache Jenas rule engine

I'm currently working on some small examples about Apache Jena. What I want to show is universal quantification.
Let's say I have balls that each have a different color. These balls are stored within boxes. I now want to determine whether these boxes only contain balls that have the same color of if they are mixed.
So basically something along these lines:
SAME_COLOR = ∃x∀y:{y in Box a → color of y = x}
I know that this is probably not possible with Jena, and can be converted to the following:
SAME_COLOR = ∃x¬∃y:{y in Box a → color of y != x}
With "not exists" Jena's "NoValue" can be used, however, this does (at least for me) not work and I don't know how to translate above logical representations in Jena. Any thoughts on this?
See the code below, which is the only way I could think of:
(?box, ex:isA, ex:Box)
(?ball, ex:isIn, ?box)
(?ball, ex:hasColor, ?color)
(?ball2, ex:isIn, ?box)
(?ball2, ex:hasColor, ?color2)
NotEqual(?color, ?color2)
->
(?box, ex:hasSomeColors, "No").
(?box, ex:isA, ex:Box)
NoValue(?box, ex:hasSomeColors)
->
(?box, ex:hasSomeColors, "Yes").
A box with mixed content now has both values "Yes" and "No".
I've ran into the same sort of problem, which is more simplified.
The question is how to get a collection of objects or count no. of objects in rule engine.
Given that res:subj ont:has res:obj_xxx(several objects), how to get this value in rule engine?
But I just found a Primitive called Remove(), which may inspire me a bit.

xtable with latex math symbols in the table

I'm trying to write this table with checkboxes using the xtable package. It would seem that the checkboxes that I've chosen are what is throwing the error. I'm just at a loss how to fix it.
library(xtable)
## I want to create a table with the names of some people in two columns
nStu = 10
## Create fake names
names = character(nStu)
for(i in 1:nStu){
names[i] = paste(LETTERS[i],rep(letters[i],5),sep='',collapse='')
}
## put check boxes behind each of the names
squares = rep('$ \\square $',nStu)
## Build the table
rosterTab = data.frame('Name'=names,'Mostly'=squares,'Sometimes'=squares, stringsAsFactors = FALSE)
## Now chop it in half and paste the halves together. (Yes, if nStu is odd, this will have to be fixed)
lTab = nStu%/%2
aTab = rosterTab[1:lTab, ]
bTab = rosterTab[(lTab+1):nStu, ]
outTab = cbind(aTab,bTab)
## Everything before this point runs fine.
outTab.tab = xtable(outTab,label=FALSE)
align(outTab.tab) = 'llcc||lcc'
print(outTab.tab, include.rownames=FALSE, sanitize.text.function = function(x){x})
The error message that I'm getting is:
Error in as.string(y) : Cannot coerce argument to a string
This error goes away if I use:
squares = rep('aaa',nStu)
Ideally, I want to get the names from a csv file (which I can do quite easily), and will use knitr to write this into a LaTeX document. (I want to do this for a bunch of input files, so automating this task seems useful to me.)
Here are some other ideas that I've considered:
A $\LaTeX$ only solution. Note, that there is one other difficulty (other than the squares not being in the input file), and that is that I would need to do some text manipulation on the strings in the input file.
Replacing the \square symbol with some other object that looks like a checkbox, that (through knitr) I can send to $\LaTeX$.

Is there any way to resize a Surface by any natural number value in ROBLOX?

I've been working with the built-in Resize function in Roblox Studio and have been using it to expand the Top Surface of multiple Parts in order to form a wall-like structure.
The only problem that has arisen when using this method is that the surface of the wall created is not even: Some Parts are higher than others.
I later discovered that this problem is due to the fact that the built-in Resize function only takes integers as it's second parameter (or "expand-by" value). Ideally I need the Parts to have the ability expand by any Real Number.
Are there any alternatives to the built-in Resize function that allow one to resize a Surface by any Real Number?
Yes, this is possible, but it actually requires a custom function to do so. With some fairly basic math we can write a simple function to accomplish such a task:
local Resize
do
local directions = {
[Enum.NormalId.Top] = {Scale=Vector3.new(0,1,0),Position=Vector3.new(0,1,0)},
[Enum.NormalId.Bottom] = {Scale=Vector3.new(0,1,0),Position=Vector3.new(0,-1,0)},
[Enum.NormalId.Right] = {Scale=Vector3.new(1,0,0),Position=Vector3.new(1,0,0)},
[Enum.NormalId.Left] = {Scale=Vector3.new(1,0,0),Position=Vector3.new(-1,0,0)},
[Enum.NormalId.Front] = {Scale=Vector3.new(0,0,1),Position=Vector3.new(0,0,1)},
[Enum.NormalId.Back] = {Scale=Vector3.new(0,0,1),Position=Vector3.new(0,0,-1)},
}
function Resize(p, d, n, c)
local prop = c and 'Position' or 'CFrame'
p.Size = p.Size + directions[d].Scale*n
p[prop] = p[prop] + directions[d].Position*(n/2)
return p.Size, p[prop]
end
end
Resize(workspace.Part, Enum.NormalId.Bottom, 10, false) --Resize workspace.Part downards by 10 studs, ignoring collisions
If you're interested more on how and why this code works the way it does, here's a link to a pastebin that's loaded with comments, which I felt would be rather ugly for the answer here: http://pastebin.com/LYKDWZnt

Lua: Working with the Modbus TCP/IP Protocol

This question is based off a previous question I asked concerning a similar topic: Lua: Working with Bit32 Library to Change States of I/O's . I'm trying to use a Lua program that, when a PLC changes the state of a coil at a given address (only two addresses will be used) then it triggers a reaction in another piece of equipment. I have some code that is basically the exact same as my previous topic. But this has to do with what this code is actually doing and not so much the bit32 library. Usually I run code I don't in understand in my Linux IDE and slowly make changes until I finally can make sense of it. But this is producing some weird reactions that I can't make sense of.
Code example:
local unitId = 1
local funcCodes = {
readCoil = 1,
readInput = 2,
readHoldingReg = 3,
readInputReg = 4,
writeCoil = 5,
presetSingleReg = 6,
writeMultipleCoils = 15,
presetMultipleReg = 16
}
local function toTwoByte(value)
return string.char(value / 255, value % 255)
end
local coil = 1
local function readCoil(s, coil)
local req = toTwoByte(0) .. toTwoByte(0) .. toTwoByte(6) .. string.char(unitId, funcCodes.readCoil) .. toTwoByte(coil - 1) .. toTwoByte(1)
s:write(req) --(s is the address of the I/O module)
local res = s:read(10)
return res:byte(10) == 1 -- returns true or false if the 10th bit is ==1 I think??? Please confirm
end
The line that sets local req is the part I'm truly not making sense of. Because of my earlier post, I understand fully about the toTwoByte function and was quickly refreshed on bits & byte manipulation (truly excellent by the way). But that particular string is the reason for this confusion. If I run this in the demo at lua.org I get back an error "lua number has no integer representation". If I separate it into the following I am given back ascii characters that represent those numbers (which I know string.char returns the ascii representation of a given digit). If I run this in my Linux IDE, it displays a bunch of boxes, each containing four digits; two on top of the other two. Now it is very hard to distinguish all of the boxes and their content as they are overlapping.
I know that there is a modbus library that I may be able to use. But I would much rather prefer to understand this as I'm fairly new to programming in general.
Why do I receive different returned results from Windows vs Linux?
What would that string "local req" look like when built at this point to the I/O module. And I don't understand how this req variable translates into the proper string that contains all of the information used to read/write to a given coil or register.
If anyone needs better examples or has further questions that I need to answer, please let me know.
Cheers!
ETA: This is with the Modbus TCP/IP Protocol, not RTU. Sorry.

Resources